fixed loglive paging related bug #4116, patch submitted by samulik; merged from MOODL...
[moodle.git] / mod / forum / post.php
CommitLineData
41905731 1<?php // $Id$
501cdbd8 2
3// Edit and save a new post to a discussion
4
16955dc6 5 require_once('../../config.php');
6 require_once('lib.php');
7
8 $reply = optional_param('reply', 0, PARAM_INT);
70e3da07 9 $forum = optional_param('forum', 0, PARAM_INT);
10 $edit = optional_param('edit', 0, PARAM_INT);
11 $delete = optional_param('delete', 0, PARAM_INT);
12 $prune = optional_param('prune',0,PARAM_INT);
13 $name = optional_param('name','',PARAM_CLEAN);
14 $confirm = optional_param('confirm',0,PARAM_INT);
501cdbd8 15
16 if (isguest()) {
c59eb341 17 $wwwroot = $CFG->wwwroot.'/login/index.php';
18 if (!empty($CFG->loginhttps)) {
19 $wwwroot = str_replace('http','https', $wwwroot);
20 }
556963f5 21
22 if (isset($forum)) { // User is starting a new discussion in a forum
23 if (! $forum = get_record('forum', 'id', $forum)) {
24 error('The forum number was incorrect');
25 }
16955dc6 26 } else if (!empty($reply)) { // User is writing a new reply
556963f5 27 if (! $parent = forum_get_post_full($reply)) {
28 error('Parent post ID was incorrect');
29 }
30 if (! $discussion = get_record('forum_discussions', 'id', $parent->discussion)) {
31 error('This post is not part of a discussion!');
32 }
33 if (! $forum = get_record('forum', 'id', $discussion->forum)) {
34 error('The forum number was incorrect');
35 }
36 }
37 if (! $course = get_record('course', 'id', $forum->course)) {
38 error('The course number was incorrect');
39 }
40 if (!$cm = get_coursemodule_from_instance('forum', $forum->id, $course->id)) { // For the logs
41 $cm->id = 0;
42 }
43
44 $strforums = get_string('modulenameplural', 'forum');
45 if ($course->category) {
46 print_header($course->shortname, $course->fullname,
47 "<a href=\"../../course/view.php?id=$course->id\">$course->shortname</a> ->
e6157a73 48 <a href=\"../forum/index.php?id=$course->id\">$strforums</a> ->
3849dae8 49 <a href=\"view.php?f=$forum->id\">".format_string($forum->name,true)."</a>", '', '', true, "", navmenu($course, $cm));
556963f5 50 } else {
51 print_header($course->shortname, $course->fullname,
e6157a73 52 "<a href=\"../forum/index.php?id=$course->id\">$strforums</a> ->
3849dae8 53 <a href=\"view.php?f=$forum->id\">".format_string($forum->name)."</a>", '', '', true, "", navmenu($course, $cm));
556963f5 54 }
c59eb341 55 notice_yesno(get_string('noguestpost', 'forum').'<br /><br />'.get_string('liketologin'),
56 $wwwroot, $_SERVER['HTTP_REFERER']);
cd8d4471 57 print_footer($course);
c59eb341 58 exit;
501cdbd8 59 }
60
8e8d0524 61 require_login(0, false); // Script is useless unless they're logged in
48d38fad 62
36b4f985 63 if ($post = data_submitted()) {
f7abd64a 64 if (empty($post->course)) {
65 error('No course was defined!');
66 }
67
68 if (!$course = get_record('course', 'id', $post->course)) {
69 error('Could not find specified course!');
70 }
71
72 if (!empty($course->lang)) { // Override current language
73 $CFG->courselang = $course->lang;
0d1db48e 74 }
501cdbd8 75
3395f2d6 76 if (empty($SESSION->fromurl)) {
77 $errordestination = "$CFG->wwwroot/mod/forum/view.php?f=$post->forum";
78 } else {
79 $errordestination = $SESSION->fromurl;
80 }
81
50d83d8f 82 $post->subject = strip_tags($post->subject, '<lang><span>'); // Strip all tags except lang
db46e49c 83
3b7d3db5 84 //$post->message = clean_text($post->message, $post->format); // Clean up any bad tags
501cdbd8 85
36257d39 86 $post->attachment = isset($_FILES['attachment']) ? $_FILES['attachment'] : NULL;
7f6689e4 87
f7abd64a 88 if (!$cm = get_coursemodule_from_instance("forum", $post->forum, $course->id)) { // For the logs
69d79bc3 89 $cm->id = 0;
90 }
91
3395f2d6 92 if (!$post->subject or !$post->message) {
93 $post->error = get_string("emptymessage", "forum");
7f6689e4 94
3395f2d6 95 } else if ($post->edit) { // Updating a post
501cdbd8 96 $post->id = $post->edit;
db290a6e 97 $message = '';
98 if (forum_update_post($post,$message)) {
8f0cd6ef 99
f7abd64a 100 add_to_log($course->id, "forum", "update post",
839f2456 101 "discuss.php?d=$post->discussion&amp;parent=$post->id", "$post->id", $cm->id);
69d79bc3 102
db290a6e 103 $timemessage = 2;
104 if (!empty($message)) { // if we're printing stuff about the file upload
105 $timemessage = 4;
106 }
107 $message .= '<br />'.get_string("postupdated", "forum");
8f0cd6ef 108
0a9f61b5 109 if ($subscribemessage = forum_post_subscription($post)) {
db290a6e 110 $timemessage = 4;
0a9f61b5 111 }
b22b0e61 112 redirect(forum_go_back_to("discuss.php?d=$post->discussion#$post->id"), $message.$subscribemessage, $timemessage);
0a9f61b5 113
501cdbd8 114 } else {
8f0cd6ef 115 error(get_string("couldnotupdate", "forum"), $errordestination);
501cdbd8 116 }
3395f2d6 117 exit;
7f6689e4 118
501cdbd8 119 } else if ($post->discussion) { // Adding a new post to an existing discussion
db290a6e 120 $message = '';
121 if ($post->id = forum_add_new_post($post,$message)) {
69d79bc3 122
f7abd64a 123 add_to_log($course->id, "forum", "add post",
839f2456 124 "discuss.php?d=$post->discussion&amp;parent=$post->id", "$post->id", $cm->id);
69d79bc3 125
0a9f61b5 126 $timemessage = 2;
db290a6e 127 if (!empty($message)) { // if we're printing stuff about the file upload
128 $timemessage = 4;
129 }
130 $message .= '<br />'.get_string("postadded", "forum", format_time($CFG->maxeditingtime));
0a9f61b5 131
132 if ($subscribemessage = forum_post_subscription($post)) {
133 $timemessage = 4;
501cdbd8 134 }
135
b22b0e61 136 redirect(forum_go_back_to("discuss.php?d=$post->discussion#$post->id"), $message.$subscribemessage, $timemessage);
0a9f61b5 137
501cdbd8 138 } else {
8f0cd6ef 139 error(get_string("couldnotadd", "forum"), $errordestination);
501cdbd8 140 }
3395f2d6 141 exit;
142
501cdbd8 143 } else { // Adding a new discussion
144 $discussion = $post;
145 $discussion->name = $post->subject;
146 $discussion->intro = $post->message;
db290a6e 147 $message = '';
148 if ($discussion->id = forum_add_discussion($discussion,$message)) {
69d79bc3 149
680afe2e 150 add_to_log($course->id, "forum", "add discussion",
69d79bc3 151 "discuss.php?d=$discussion->id", "$discussion->id", $cm->id);
152
0a9f61b5 153 $timemessage = 2;
db290a6e 154 if (!empty($message)) { // if we're printing stuff about the file upload
155 $timemessage = 4;
156 }
157 $message .= '<br />'.get_string("postadded", "forum", format_time($CFG->maxeditingtime));
8f0cd6ef 158
0a9f61b5 159 if ($subscribemessage = forum_post_subscription($discussion)) {
160 $timemessage = 4;
161 }
162
163 redirect(forum_go_back_to("view.php?f=$post->forum"), $message.$subscribemessage, $timemessage);
164
501cdbd8 165 } else {
8f0cd6ef 166 error(get_string("couldnotadd", "forum"), $errordestination);
501cdbd8 167 }
3395f2d6 168 exit;
501cdbd8 169 }
501cdbd8 170 }
171
213e8cc6 172 if ($usehtmleditor = can_use_richtext_editor()) {
173 $defaultformat = FORMAT_HTML;
213e8cc6 174 } else {
175 $defaultformat = FORMAT_MOODLE;
176 }
501cdbd8 177
3395f2d6 178 if (isset($post->error)) { // User is re-editing a failed posting
179
180 // Set up all the required objects again, and reuse the same $post
181
182 if (! $forum = get_record("forum", "id", $post->forum)) {
183 error("The forum number was incorrect ($post->forum)");
184 }
185
186 if (! $course = get_record("course", "id", $forum->course)) {
187 error("The course number was incorrect ($forum->course)");
188 }
189
190 if (!empty($post->parent)) {
191 if (! $parent = forum_get_post_full($post->parent)) {
192 error("Parent post ID was incorrect ($post->parent)");
193 }
194 }
195
196 if (!empty($post->discussion)) {
197 if (! $discussion = get_record("forum_discussions", "id", $post->discussion)) {
198 error("This post is not part of a discussion! ($post->discussion)");
199 }
200 }
201
70e3da07 202 } else if (!empty($forum)) { // User is starting a new discussion in a forum
501cdbd8 203
607809b3 204 $SESSION->fromurl = $_SERVER["HTTP_REFERER"];
501cdbd8 205
206 if (! $forum = get_record("forum", "id", $forum)) {
207 error("The forum number was incorrect ($forum)");
208 }
209 if (! $course = get_record("course", "id", $forum->course)) {
3395f2d6 210 error("The course number was incorrect ($forum->course)");
501cdbd8 211 }
212
11b0c469 213 if (! forum_user_can_post_discussion($forum)) {
501cdbd8 214 error("Sorry, but you can not post a new discussion in this forum.");
215 }
216
80602101 217 if ($cm = get_coursemodule_from_instance("forum", $forum->id, $course->id)) {
218 if (!$cm->visible and !isteacher($course->id)) {
219 error(get_string("activityiscurrentlyhidden"));
220 }
221 }
222
501cdbd8 223 // Load up the $post variable.
224
225 $post->course = $course->id;
226 $post->forum = $forum->id;
227 $post->discussion = 0; // ie discussion # not defined yet
228 $post->parent = 0;
229 $post->subject = "";
ebc3bd2b 230 $post->userid = $USER->id;
501cdbd8 231 $post->message = "";
213e8cc6 232 $post->format = $defaultformat;
501cdbd8 233
2862b309 234 $post->groupid = get_current_group($course->id);
235 if (isteacheredit($course->id) and $post->groupid == 0) {
236 $post->groupid = -1;
237 }
238
11b0c469 239 forum_set_return();
240
16955dc6 241 } else if (!empty($reply)) { // User is writing a new reply
501cdbd8 242
11b0c469 243 if (! $parent = forum_get_post_full($reply)) {
29ad118c 244 error("Parent post ID was incorrect");
501cdbd8 245 }
246 if (! $discussion = get_record("forum_discussions", "id", $parent->discussion)) {
29ad118c 247 error("This post is not part of a discussion!");
501cdbd8 248 }
249 if (! $forum = get_record("forum", "id", $discussion->forum)) {
250 error("The forum number was incorrect ($discussion->forum)");
251 }
252 if (! $course = get_record("course", "id", $discussion->course)) {
253 error("The course number was incorrect ($discussion->course)");
254 }
6c506ca7 255
256 if (! forum_user_can_post($forum)) {
257 error("Sorry, but you can not post in this forum.");
258 }
02509fe6 259
260 if ($cm = get_coursemodule_from_instance("forum", $forum->id, $course->id)) {
261 if (groupmode($course, $cm) and !isteacheredit($course->id)) { // Make sure user can post here
63e20b88 262 $mygroupid = mygroupid($course->id);
fa22fd5f 263 if (!((empty($mygroupid) and $discussion->groupid == -1) || (ismember($discussion->groupid)/*$mygroupid == $discussion->groupid*/))) {
02509fe6 264 error("Sorry, but you can not post in this discussion.");
265 }
266 }
80602101 267 if (!$cm->visible and !isteacher($course->id)) {
268 error(get_string("activityiscurrentlyhidden"));
269 }
02509fe6 270 }
271
501cdbd8 272 // Load up the $post variable.
273
274 $post->course = $course->id;
275 $post->forum = $forum->id;
276 $post->discussion = $parent->discussion;
277 $post->parent = $parent->id;
278 $post->subject = $parent->subject;
ebc3bd2b 279 $post->userid = $USER->id;
501cdbd8 280 $post->message = "";
213e8cc6 281 $post->format = $defaultformat;
501cdbd8 282
e9584ca3 283 $strre = get_string('re', 'forum');
284 if (!(substr($post->subject, 0, strlen($strre)) == $strre)) {
285 $post->subject = $strre.' '.$post->subject;
501cdbd8 286 }
287
b22b0e61 288 unset($SESSION->fromdiscussion);
501cdbd8 289
70e3da07 290 } else if (!empty($edit)) { // User is editing their own post
501cdbd8 291
b8be40ce 292 $adminedit = (isadmin() and !empty($CFG->admineditalways));
293
11b0c469 294 if (! $post = forum_get_post_full($edit)) {
501cdbd8 295 error("Post ID was incorrect");
296 }
b8be40ce 297 if (($post->userid <> $USER->id) and !$adminedit) {
501cdbd8 298 error("You can't edit other people's posts!");
299 }
b8be40ce 300 if (((time() - $post->created) > $CFG->maxeditingtime) and !$adminedit) {
cf38360f 301 error( get_string("maxtimehaspassed", "forum", format_time($CFG->maxeditingtime)) );
501cdbd8 302 }
303 if ($post->parent) {
11b0c469 304 if (! $parent = forum_get_post_full($post->parent)) {
501cdbd8 305 error("Parent post ID was incorrect ($post->parent)");
306 }
307 }
308 if (! $discussion = get_record("forum_discussions", "id", $post->discussion)) {
309 error("This post is not part of a discussion! ($reply)");
310 }
311 if (! $forum = get_record("forum", "id", $discussion->forum)) {
312 error("The forum number was incorrect ($discussion->forum)");
313 }
314 if (! $course = get_record("course", "id", $discussion->course)) {
315 error("The course number was incorrect ($discussion->course)");
316 }
317
318 // Load up the $post variable.
319
320 $post->edit = $edit;
321
322 $post->course = $course->id;
323 $post->forum = $forum->id;
324
b22b0e61 325 unset($SESSION->fromdiscussion);
501cdbd8 326
327
70e3da07 328 } else if (!empty($delete)) { // User is deleting a post
501cdbd8 329
11b0c469 330 if (! $post = forum_get_post_full($delete)) {
501cdbd8 331 error("Post ID was incorrect");
332 }
501cdbd8 333 if (! $discussion = get_record("forum_discussions", "id", $post->discussion)) {
334 error("This post is not part of a discussion!");
335 }
64eacd6f 336 if (! $forum = get_record("forum", "id", $discussion->forum)) {
337 error("The forum number was incorrect ($discussion->forum)");
338 }
ebc3bd2b 339 if (($post->userid <> $USER->id) and !isteacher($forum->course)) {
64eacd6f 340 error("You can't delete other people's posts!");
341 }
0d1db48e 342 if (!empty($forum->course)) {
343 if ($course = get_record('course', 'id', $forum->course)) {
344 if (!empty($course->lang)) {
345 $CFG->courselang = $course->lang;
346 }
347 }
348 }
501cdbd8 349
b82faacd 350 $replycount = forum_count_replies($post);
351
70e3da07 352 if (!empty($confirm)) { // User has confirmed the delete
501cdbd8 353
354 if ($post->totalscore) {
8f0cd6ef 355 notice(get_string("couldnotdeleteratings", "forum"),
11b0c469 356 forum_go_back_to("discuss.php?d=$post->discussion"));
501cdbd8 357
b82faacd 358 } else if ($replycount && !isteacher($course->id)) {
cf38360f 359 error(get_string("couldnotdeletereplies", "forum"),
8203d211 360 forum_go_back_to("discuss.php?d=$post->discussion"));
501cdbd8 361
362 } else {
69d79bc3 363 if (!$cm = get_coursemodule_from_instance("forum", $forum->id, $forum->course)) { // For the logs
364 $cm->id = 0;
365 }
501cdbd8 366 if (! $post->parent) { // post is a discussion topic as well, so delete discussion
64eacd6f 367 if ($forum->type == "single") {
8f0cd6ef 368 notice("Sorry, but you are not allowed to delete that discussion!",
64eacd6f 369 forum_go_back_to("discuss.php?d=$post->discussion"));
370 }
501cdbd8 371 forum_delete_discussion($discussion);
372
8f0cd6ef 373 add_to_log($discussion->course, "forum", "delete discussion",
b17333be 374 "view.php?id=$cm->id", "$forum->id", $cm->id);
69d79bc3 375
8f0cd6ef 376 redirect("view.php?f=$discussion->forum",
cf38360f 377 get_string("deleteddiscussion", "forum"), 1);
501cdbd8 378
b82faacd 379 } else if (forum_delete_post($post, isteacher($course->id))) {
501cdbd8 380
8f0cd6ef 381 add_to_log($discussion->course, "forum", "delete post",
69d79bc3 382 "discuss.php?d=$post->discussion", "$post->id", $cm->id);
383
b82faacd 384 $feedback = $replycount ? get_string('deletedposts', 'forum') : get_string('deletedpost', 'forum');
385 redirect(forum_go_back_to("discuss.php?d=$post->discussion"), $feedback, 1);
501cdbd8 386 } else {
387 error("An error occurred while deleting record $post->id");
388 }
389 }
390
391
392 } else { // User just asked to delete something
393
11b0c469 394 forum_set_return();
501cdbd8 395
b82faacd 396 if ($replycount) {
397 if (!isteacher($course->id)) {
398 error(get_string("couldnotdeletereplies", "forum"),
399 forum_go_back_to("discuss.php?d=$post->discussion"));
400 }
401 print_header();
402 notice_yesno(get_string("deletesureplural", "forum", $replycount+1),
403 "post.php?delete=$delete&amp;confirm=$delete",
404 $_SERVER["HTTP_REFERER"]);
405
406 forum_print_post($post, $course->id, $ownpost=false, $reply=false, $link=false);
407 if (empty($post->edit)) {
eaf50aef 408 if (forum_tp_can_track_forums($forum) && forum_tp_is_tracked($forum)) {
b82faacd 409 $user_read_array = forum_tp_get_discussion_read_records($USER->id, $discussion->id);
410 } else {
411 $user_read_array = array();
412 }
413 forum_print_posts_nested($post->id, $course->id, false, false, $user_read_array, $forum->id);
414 }
415 } else {
416 print_header();
417 notice_yesno(get_string("deletesure", "forum", $replycount),
418 "post.php?delete=$delete&amp;confirm=$delete",
419 $_SERVER["HTTP_REFERER"]);
420 forum_print_post($post, $forum->course, $ownpost=false, $reply=false, $link=false);
421 }
8f0cd6ef 422
501cdbd8 423 }
839f2456 424 print_footer($course);
501cdbd8 425 die;
426
427
70e3da07 428 } else if (!empty($prune)) { // Teacher is pruning
8f0cd6ef 429
0d5da5dd 430 if (!$post = forum_get_post_full($prune)) {
cf84431b 431 error("Post ID was incorrect");
432 }
0d5da5dd 433 if (!$discussion = get_record("forum_discussions", "id", $post->discussion)) {
cf84431b 434 error("This post is not part of a discussion!");
435 }
0d5da5dd 436 if (!$forum = get_record("forum", "id", $discussion->forum)) {
cf84431b 437 error("The forum number was incorrect ($discussion->forum)");
438 }
439 if (!isteacher($forum->course)) {
4d35d88b 440 error("You can't split discussions!");
cf84431b 441 }
442 if (!$post->parent) {
443 error('This is already the first post in the discussion');
444 }
0d5da5dd 445 if (!$cm = get_coursemodule_from_instance("forum", $forum->id, $forum->course)) { // For the logs
446 $cm->id = 0;
447 }
cf84431b 448
70e3da07 449 if (!empty($name)) { // User has confirmed the prune
8f0cd6ef 450
cf84431b 451 $newdiscussion->course = $discussion->course;
452 $newdiscussion->forum = $discussion->forum;
453 $newdiscussion->name = $name;
454 $newdiscussion->firstpost = $post->id;
455 $newdiscussion->userid = $discussion->userid;
456 $newdiscussion->groupid = $discussion->groupid;
457 $newdiscussion->assessed = $discussion->assessed;
458 $newdiscussion->usermodified = $post->userid;
8f0cd6ef 459
cf84431b 460 if (!$newid = insert_record('forum_discussions', $newdiscussion)) {
461 error('Could not create new discussion');
462 }
8f0cd6ef 463
13152de4 464 $newpost->id = $post->id;
465 $newpost->parent = 0;
466 $newpost->subject = $name;
d078ee9b 467
13152de4 468 if (!update_record("forum_posts", $newpost)) {
d078ee9b 469 error('Could not update the original post');
470 }
471
cf84431b 472 forum_change_discussionid($post->id, $newid);
8f0cd6ef 473
1da8c568 474 // update last post in each discussion
475 forum_discussion_update_last_post($discussion->id);
476 forum_discussion_update_last_post($newid);
cf84431b 477
8f0cd6ef 478 add_to_log($discussion->course, "forum", "prune post",
cf84431b 479 "discuss.php?d=$newid", "$post->id", $cm->id);
480
d078ee9b 481 redirect(forum_go_back_to("discuss.php?d=$newid"), get_string("prunedpost", "forum"), 1);
cf84431b 482
483 } else { // User just asked to prune something
484
485 $course = get_record('course', 'id', $forum->course);
486 $strforums = get_string("modulenameplural", "forum");
c78ac798 487 print_header_simple(format_string($discussion->name).": ".format_string($post->subject), "",
8f0cd6ef 488 "<a href=\"../forum/index.php?id=$course->id\">$strforums</a> ->
3849dae8 489 <a href=\"view.php?f=$forum->id\">".format_string($forum->name,true)."</a> ->
17dc3f3c 490 <a href=\"discuss.php?d=$discussion->id\">".format_string($post->subject,true)."</a> -> ".
cf84431b 491 get_string("prune", "forum"), '', "", true, "", navmenu($course, $cm));
8f0cd6ef 492
cf84431b 493 print_heading(get_string('pruneheading', 'forum'));
d078ee9b 494 echo '<center>';
8f0cd6ef 495
cf84431b 496 include('prune.html');
8f0cd6ef 497
cf84431b 498 forum_print_post($post, $forum->course, $ownpost=false, $reply=false, $link=false);
839f2456 499 echo '</center>';
cf84431b 500 }
839f2456 501 print_footer($course);
cf84431b 502 die;
503
504
501cdbd8 505 } else {
506 error("No operation specified");
507
508 }
509
510
8f0cd6ef 511 // To get here they need to edit a post, and the $post
501cdbd8 512 // variable will be loaded with all the particulars,
513 // so bring up the form.
514
515 // $course, $forum are defined. $discussion is for edit and reply only.
516
ec81373f 517 $cm = get_coursemodule_from_instance("forum", $forum->id, $course->id);
518
519 require_login($course->id, false, $cm);
501cdbd8 520
dfc9ba9b 521
501cdbd8 522 if ($post->discussion) {
9fa49e22 523 if (! $toppost = get_record("forum_posts", "discussion", $post->discussion, "parent", 0)) {
501cdbd8 524 error("Could not find top parent of post $post->id");
525 }
526 } else {
680afe2e 527 $toppost->subject = ($forum->type == "news") ? get_string("addanewtopic", "forum") :
21da9db8 528 get_string("addanewdiscussion", "forum");
501cdbd8 529 }
530
3bbde520 531 if (empty($post->subject)) {
0ae5e5ea 532 $formstart = "theform.subject";
3bbde520 533 } else {
534 $formstart = "";
501cdbd8 535 }
536
537 if ($post->parent) {
17dc3f3c 538 $navtail = "<a href=\"discuss.php?d=$discussion->id\">".format_string($toppost->subject,true)."</a> -> ".get_string("editing", "forum");
501cdbd8 539 } else {
17dc3f3c 540 $navtail = format_string($toppost->subject);
501cdbd8 541 }
542
9c9f7d77 543 if (empty($post->edit)) {
544 $post->edit = "";
545 }
546
cf38360f 547 $strforums = get_string("modulenameplural", "forum");
548
73bb0835 549
3849dae8 550 $navmiddle = "<a href=\"../forum/index.php?id=$course->id\">$strforums</a> -> <a href=\"view.php?f=$forum->id\">".format_string($forum->name,true)."</a>";
501cdbd8 551
f37da850 552 if (empty($discussion->name)) {
8cb091e6 553 if (empty($discussion)) {
554 $discussion = new object;
555 }
9c9f7d77 556 $discussion->name = $forum->name;
557 }
558
501cdbd8 559 if ($course->category) {
c78ac798 560 print_header("$course->shortname: ".format_string($discussion->name).": ".format_string($toppost->subject), "$course->fullname",
325505f4 561 "<a href=\"../../course/view.php?id=$course->id\">$course->shortname</a> ->
3bbde520 562 $navmiddle -> $navtail", $formstart, "", true, "", navmenu($course, $cm));
680afe2e 563
501cdbd8 564 } else {
c78ac798 565 print_header("$course->shortname: ".format_string($discussion->name).": ".format_string($toppost->subject), "$course->fullname",
9c9f7d77 566 "$navmiddle -> $navtail", "$formstart", "", true, "", navmenu($course, $cm));
501cdbd8 567
568 }
569
3395f2d6 570 if (!empty($parent)) {
11b0c469 571 forum_print_post($parent, $course->id, $ownpost=false, $reply=false, $link=false);
f8029045 572 if (empty($post->edit)) {
eaf50aef 573 if (forum_tp_can_track_forums($forum) && forum_tp_is_tracked($forum)) {
f37da850 574 $user_read_array = forum_tp_get_discussion_read_records($USER->id, $discussion->id);
575 } else {
576 $user_read_array = array();
577 }
e6157a73 578 forum_print_posts_threaded($parent->id, $course->id, 0, false, false, $user_read_array, $discussion->forum);
f8029045 579 }
556963f5 580 print_heading(get_string("yourreply", "forum").':');
501cdbd8 581 } else {
21da9db8 582 $forum->intro = trim($forum->intro);
583 if (!empty($forum->intro)) {
584 print_simple_box(format_text($forum->intro), 'center');
585 }
586 print_heading(get_string('yournewtopic', 'forum'));
501cdbd8 587 }
556963f5 588 echo '<center>';
3395f2d6 589 if (!empty($post->error)) {
590 notify($post->error);
591 }
556963f5 592 echo '</center>';
501cdbd8 593
d30867b0 594 print_simple_box_start("center");
501cdbd8 595 require("post.html");
596 print_simple_box_end();
597
4b00b4b3 598 if ($usehtmleditor) {
76138908 599 use_html_editor("message");
4b00b4b3 600 }
601
501cdbd8 602 print_footer($course);
603
604
605?>