Added some set_time_limit()s in case of slow servers timing out.
[moodle-linuxchix.git] / mod / forum / post.php
blobc7ef23f0089d6b74d494ec5a51c4fd72ab6d4d98
1 <?php // $Id$
3 // Edit and save a new post to a discussion
5 require_once('../../config.php');
6 require_once('lib.php');
7 require_once('post_form.php');
9 $reply = optional_param('reply', 0, PARAM_INT);
10 $forum = optional_param('forum', 0, PARAM_INT);
11 $edit = optional_param('edit', 0, PARAM_INT);
12 $delete = optional_param('delete', 0, PARAM_INT);
13 $prune = optional_param('prune', 0, PARAM_INT);
14 $name = optional_param('name', '', PARAM_CLEAN);
15 $confirm = optional_param('confirm', 0, PARAM_INT);
18 //these page_params will be passed as hidden variables later in the form.
19 $page_params = array('reply'=>$reply, 'forum'=>$forum, 'edit'=>$edit);
21 $sitecontext = get_context_instance(CONTEXT_SYSTEM);
23 if (has_capability('moodle/legacy:guest', $sitecontext, NULL, false)) {
25 $wwwroot = $CFG->wwwroot.'/login/index.php';
26 if (!empty($CFG->loginhttps)) {
27 $wwwroot = str_replace('http', 'https', $wwwroot);
30 if (!empty($forum)) { // User is starting a new discussion in a forum
31 if (! $forum = get_record('forum', 'id', $forum)) {
32 error('The forum number was incorrect');
34 } else if (!empty($reply)) { // User is writing a new reply
35 if (! $parent = forum_get_post_full($reply)) {
36 error('Parent post ID was incorrect');
38 if (! $discussion = get_record('forum_discussions', 'id', $parent->discussion)) {
39 error('This post is not part of a discussion!');
41 if (! $forum = get_record('forum', 'id', $discussion->forum)) {
42 error('The forum number was incorrect');
45 if (! $course = get_record('course', 'id', $forum->course)) {
46 error('The course number was incorrect');
49 if (!$cm = get_coursemodule_from_instance('forum', $forum->id, $course->id)) { // For the logs
50 error('Could not get the course module for the forum instance.');
51 } else {
52 $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
55 $strforums = get_string('modulenameplural', 'forum');
57 if (!get_referer()) { // No referer - probably coming in via email See MDL-9052
58 require_login();
61 $crumbs[] = array('name' => get_string("forums", "forum"), 'link' => "../forum/view.php?f=$forum->id", 'type' => 'activity');
62 $crumbs[] = array('name' => format_string($forum->name,true), 'link' => '../forum/index.php?id=$course->id', 'type' => 'activityinstance');
64 $navigation = build_navigation($crumbs);
67 print_header($course->shortname, $course->fullname, $navigation, '' , '', true, "", navmenu($course, $cm));
69 notice_yesno(get_string('noguestpost', 'forum').'<br /><br />'.get_string('liketologin'),
70 $wwwroot, get_referer(false));
71 print_footer($course);
72 exit;
75 require_login(0, false); // Script is useless unless they're logged in
77 if (!empty($forum)) { // User is starting a new discussion in a forum
78 if (! $forum = get_record("forum", "id", $forum)) {
79 error("The forum number was incorrect ($forum)");
81 if (! $course = get_record("course", "id", $forum->course)) {
82 error("The course number was incorrect ($forum->course)");
84 $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
85 if (! forum_user_can_post_discussion($forum)) {
86 if (has_capability('moodle/legacy:guest', $coursecontext, NULL, false)) { // User is a guest here!
87 $SESSION->wantsurl = $FULLME;
88 $SESSION->enrolcancel = $_SERVER['HTTP_REFERER'];
89 redirect($CFG->wwwroot.'/course/enrol.php?id='.$course->id, get_string('youneedtoenrol'));
90 } else {
91 print_error('nopostforum', 'forum');
95 if ($cm = get_coursemodule_from_instance("forum", $forum->id, $course->id)) {
96 if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', $coursecontext)) {
97 error(get_string("activityiscurrentlyhidden"));
101 $SESSION->fromurl = $_SERVER["HTTP_REFERER"];
104 // Load up the $post variable.
106 $post = new object();
107 $post->course = $course->id;
108 $post->forum = $forum->id;
109 $post->discussion = 0; // ie discussion # not defined yet
110 $post->parent = 0;
111 $post->subject = '';
112 $post->userid = $USER->id;
113 $post->message = '';
115 $post->groupid = get_current_group($course->id);
116 if ($post->groupid == 0) {
117 $post->groupid = -1;
120 forum_set_return();
122 } else if (!empty($reply)) { // User is writing a new reply
124 if (! $parent = forum_get_post_full($reply)) {
125 error("Parent post ID was incorrect");
127 if (! $discussion = get_record("forum_discussions", "id", $parent->discussion)) {
128 error("This post is not part of a discussion!");
130 if (! $forum = get_record("forum", "id", $discussion->forum)) {
131 error("The forum number was incorrect ($discussion->forum)");
133 if (! $course = get_record("course", "id", $discussion->course)) {
134 error("The course number was incorrect ($discussion->course)");
137 $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
138 $modcontext = get_context_instance(CONTEXT_MODULE, $forum->id);
140 if (! forum_user_can_post($forum)) {
141 if (has_capability('moodle/legacy:guest', $coursecontext, NULL, false)) { // User is a guest here!
142 $SESSION->wantsurl = $FULLME;
143 $SESSION->enrolcancel = $_SERVER['HTTP_REFERER'];
144 redirect($CFG->wwwroot.'/course/enrol.php?id='.$course->id, get_string('youneedtoenrol'));
145 } else {
146 print_error('nopostforum', 'forum');
150 if ($cm = get_coursemodule_from_instance("forum", $forum->id, $course->id)) {
151 if (groupmode($course, $cm)) { // Make sure user can post here
152 $mygroupid = mygroupid($course->id);
153 if (!((empty($mygroupid) and $discussion->groupid == -1)
154 || (ismember($discussion->groupid)/*$mygroupid == $discussion->groupid*/)
155 || has_capability('moodle/site:accessallgroups', $modcontext, NULL, false) )) {
156 print_error('nopostdiscussion', 'forum');
159 if (!$cm->visible and !has_capability('moodle/course:manageactivities', $coursecontext)) {
160 error(get_string("activityiscurrentlyhidden"));
164 // Load up the $post variable.
166 $post = new object();
167 $post->course = $course->id;
168 $post->forum = $forum->id;
169 $post->discussion = $parent->discussion;
170 $post->parent = $parent->id;
171 $post->subject = $parent->subject;
172 $post->userid = $USER->id;
173 $post->message = '';
175 $strre = get_string('re', 'forum');
176 if (!(substr($post->subject, 0, strlen($strre)) == $strre)) {
177 $post->subject = $strre.' '.$post->subject;
180 unset($SESSION->fromdiscussion);
182 } else if (!empty($edit)) { // User is editing their own post
184 if (! $post = forum_get_post_full($edit)) {
185 error("Post ID was incorrect");
187 if ($post->parent) {
188 if (! $parent = forum_get_post_full($post->parent)) {
189 error("Parent post ID was incorrect ($post->parent)");
193 if (! $discussion = get_record("forum_discussions", "id", $post->discussion)) {
194 error("This post is not part of a discussion! ($edit)");
196 if (! $forum = get_record("forum", "id", $discussion->forum)) {
197 error("The forum number was incorrect ($discussion->forum)");
199 if (! $course = get_record("course", "id", $discussion->course)) {
200 error("The course number was incorrect ($discussion->course)");
202 if (!$cm = get_coursemodule_from_instance("forum", $forum->id, $course->id)) {
203 error('Could not get the course module for the forum instance.');
204 } else {
205 $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
207 if (!($forum->type == 'news' && !$post->parent && $discussion->timestart > time())) {
208 if (((time() - $post->created) > $CFG->maxeditingtime) and
209 !has_capability('mod/forum:editanypost', $modcontext)) {
210 error( get_string("maxtimehaspassed", "forum", format_time($CFG->maxeditingtime)) );
213 if (($post->userid <> $USER->id) and
214 !has_capability('mod/forum:editanypost', $modcontext)) {
215 error("You can't edit other people's posts!");
219 // Load up the $post variable.
220 $post->edit = $edit;
221 $post->course = $course->id;
222 $post->forum = $forum->id;
224 trusttext_prepare_edit($post->message, $post->format, can_use_html_editor(), $modcontext);
226 unset($SESSION->fromdiscussion);
229 }else if (!empty($delete)) { // User is deleting a post
231 if (! $post = forum_get_post_full($delete)) {
232 error("Post ID was incorrect");
234 if (! $discussion = get_record("forum_discussions", "id", $post->discussion)) {
235 error("This post is not part of a discussion!");
237 if (! $forum = get_record("forum", "id", $discussion->forum)) {
238 error("The forum number was incorrect ($discussion->forum)");
240 if (!$cm = get_coursemodule_from_instance("forum", $forum->id, $forum->course)) {
241 error('Could not get the course module for the forum instance.');
243 if (!$course = get_record('course', 'id', $forum->course)) {
244 error('Incorrect course');
247 require_login($course, false, $cm);
248 $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
250 if ( !(($post->userid == $USER->id && has_capability('mod/forum:deleteownpost', $modcontext))
251 || has_capability('mod/forum:deleteanypost', $modcontext)) ) {
252 error("You can't delete this post!");
256 $replycount = forum_count_replies($post);
258 if (!empty($confirm)) { // User has confirmed the delete
260 if ($post->totalscore) {
261 notice(get_string("couldnotdeleteratings", "forum"),
262 forum_go_back_to("discuss.php?d=$post->discussion"));
264 } else if ($replycount && !has_capability('mod/forum:deleteanypost', $modcontext)) {
265 error(get_string("couldnotdeletereplies", "forum"),
266 forum_go_back_to("discuss.php?d=$post->discussion"));
268 } else {
269 if (! $post->parent) { // post is a discussion topic as well, so delete discussion
270 if ($forum->type == 'single') {
271 notice("Sorry, but you are not allowed to delete that discussion!",
272 forum_go_back_to("discuss.php?d=$post->discussion"));
274 forum_delete_discussion($discussion);
276 add_to_log($discussion->course, "forum", "delete discussion",
277 "view.php?id=$cm->id", "$forum->id", $cm->id);
279 redirect("view.php?f=$discussion->forum");
281 } else if (forum_delete_post($post, has_capability('mod/forum:deleteanypost', $modcontext))) {
283 if ($forum->type == 'single') {
284 // Single discussion forums are an exception. We show
285 // the forum itself since it only has one discussion
286 // thread.
287 $discussionurl = "view.php?f=$forum->id";
288 } else {
289 $discussionurl = "discuss.php?d=$post->discussion";
292 add_to_log($discussion->course, "forum", "delete post", $discussionurl, "$post->id", $cm->id);
294 redirect(forum_go_back_to($discussionurl));
295 } else {
296 error("An error occurred while deleting record $post->id");
301 } else { // User just asked to delete something
303 forum_set_return();
305 if ($replycount) {
306 if (!has_capability('mod/forum:deleteanypost', $modcontext)) {
307 error(get_string("couldnotdeletereplies", "forum"),
308 forum_go_back_to("discuss.php?d=$post->discussion"));
310 print_header();
311 notice_yesno(get_string("deletesureplural", "forum", $replycount+1),
312 "post.php?delete=$delete&amp;confirm=$delete",
313 $CFG->wwwroot.'/mod/forum/discuss.php?d='.$post->discussion.'#p'.$post->id);
315 forum_print_post($post, $course->id, $ownpost=false, $reply=false, $link=false);
316 if (empty($post->edit)) {
317 if (forum_tp_can_track_forums($forum) && forum_tp_is_tracked($forum)) {
318 $user_read_array = forum_tp_get_discussion_read_records($USER->id, $discussion->id);
319 } else {
320 $user_read_array = array();
322 forum_print_posts_nested($post->id, $course->id, false, false, $user_read_array, $forum->id);
324 } else {
325 print_header();
326 notice_yesno(get_string("deletesure", "forum", $replycount),
327 "post.php?delete=$delete&amp;confirm=$delete",
328 $CFG->wwwroot.'/mod/forum/discuss.php?d='.$post->discussion.'#p'.$post->id);
329 forum_print_post($post, $forum->course, $ownpost=false, $reply=false, $link=false);
333 print_footer($course);
334 die;
337 } else if (!empty($prune)) { // Pruning
339 if (!$post = forum_get_post_full($prune)) {
340 error("Post ID was incorrect");
342 if (!$discussion = get_record("forum_discussions", "id", $post->discussion)) {
343 error("This post is not part of a discussion!");
345 if (!$forum = get_record("forum", "id", $discussion->forum)) {
346 error("The forum number was incorrect ($discussion->forum)");
348 if ($forum->type == 'single') {
349 error('Discussions from this forum cannot be split');
351 if (!$post->parent) {
352 error('This is already the first post in the discussion');
354 if (!$cm = get_coursemodule_from_instance("forum", $forum->id, $forum->course)) { // For the logs
355 error('Could not get the course module for the forum instance.');
356 } else {
357 $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
359 if (!has_capability('mod/forum:splitdiscussions', $modcontext)) {
360 error("You can't split discussions!");
363 if (!empty($name)) { // User has confirmed the prune
365 $newdiscussion = new object();
366 $newdiscussion->course = $discussion->course;
367 $newdiscussion->forum = $discussion->forum;
368 $newdiscussion->name = $name;
369 $newdiscussion->firstpost = $post->id;
370 $newdiscussion->userid = $discussion->userid;
371 $newdiscussion->groupid = $discussion->groupid;
372 $newdiscussion->assessed = $discussion->assessed;
373 $newdiscussion->usermodified = $post->userid;
374 $newdiscussion->timestart = $discussion->timestart;
375 $newdiscussion->timeend = $discussion->timeend;
377 if (!$newid = insert_record('forum_discussions', $newdiscussion)) {
378 error('Could not create new discussion');
381 $newpost = new object();
382 $newpost->id = $post->id;
383 $newpost->parent = 0;
384 $newpost->subject = $name;
386 if (!update_record("forum_posts", $newpost)) {
387 error('Could not update the original post');
390 forum_change_discussionid($post->id, $newid);
392 // update last post in each discussion
393 forum_discussion_update_last_post($discussion->id);
394 forum_discussion_update_last_post($newid);
396 add_to_log($discussion->course, "forum", "prune post",
397 "discuss.php?d=$newid", "$post->id", $cm->id);
399 redirect(forum_go_back_to("discuss.php?d=$newid"));
401 } else { // User just asked to prune something
403 $course = get_record('course', 'id', $forum->course);
404 $strforums = get_string("modulenameplural", "forum");
406 $crumbs[] = array('name' => $strforums, 'link' => "../forum/index.php?id=$course->id", 'type' => 'activity');
407 $crumbs[] = array('name' => $forum->name, 'link' => "view.php?f=$forum->id", 'type' => 'activityinstance');
408 $crumbs[] = array('name' => format_string($post->subject, true), 'link' => "discuss.php?d=$discussion->id", 'type' => 'title');
409 $crumbs[] = array('name' => get_string("prune", "forum"), 'link' => '', 'type' => 'title');
411 $navigation = build_navigation($crumbs);
413 print_header_simple(format_string($discussion->name).": ".format_string($post->subject), "", $navigation, '', "", true, "", navmenu($course, $cm));
415 print_heading(get_string('pruneheading', 'forum'));
416 echo '<center>';
418 include('prune.html');
420 forum_print_post($post, $forum->course, $ownpost=false, $reply=false, $link=false);
421 echo '</center>';
423 print_footer($course);
424 die;
425 } else {
426 error("No operation specified");
430 if (!isset($coursecontext)) {
431 // Has not yet been set by post.php.
432 $coursecontext = get_context_instance(CONTEXT_COURSE, $forum->course);
435 if (!$cm = get_coursemodule_from_instance('forum', $forum->id, $course->id)) { // For the logs
436 error('Could not get the course module for the forum instance.');
438 $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
440 $mform_post = new mod_forum_post_form('post.php', array('course'=>$course, 'coursecontext'=>$coursecontext, 'modcontext'=>$modcontext, 'forum'=>$forum, 'post'=>$post));
442 if ($fromform = $mform_post->get_data()) {
445 require_login($course, false, $cm);
447 if (empty($SESSION->fromurl)) {
448 $errordestination = "$CFG->wwwroot/mod/forum/view.php?f=$forum->id";
449 } else {
450 $errordestination = $SESSION->fromurl;
453 // TODO add attachment processing
454 //$fromform->attachment = isset($_FILES['attachment']) ? $_FILES['attachment'] : NULL;
456 trusttext_after_edit($fromform->message, $modcontext);
458 if ($fromform->edit) { // Updating a post
459 $fromform->id = $fromform->edit;
460 $message = '';
462 //fix for bug #4314
463 if (!$realpost = get_record('forum_posts', 'id', $fromform->id)) {
464 $realpost = new object;
465 $realpost->userid = -1;
469 // if user has edit any post capability
470 // or has either startnewdiscussion or reply capability and is editting own post
471 // then he can proceed
472 // MDL-7066
473 if ( !(($realpost->userid == $USER->id && (has_capability('mod/forum:replypost', $modcontext)
474 || has_capability('mod/forum:startdiscussion', $modcontext))) ||
475 has_capability('mod/forum:editanypost', $modcontext)) ) {
476 error("You can not update this post");
479 if ($forum->type == 'news' && !$fromform->parent) {
480 $updatediscussion = new object;
481 $updatediscussion->id = $fromform->discussion;
482 $updatediscussion->timestart = $fromform->timestart;
483 $updatediscussion->timeend = $fromform->timeend;
484 if (!update_record('forum_discussions', $updatediscussion)) {
485 error(get_string("couldnotupdate", "forum"), $errordestination);
489 $updatepost=$fromform; //realpost
490 $updatepost->forum=$forum->id;
491 if (!forum_update_post($updatepost, $message)) {
492 error(get_string("couldnotupdate", "forum"), $errordestination);
495 $timemessage = 2;
496 if (!empty($message)) { // if we're printing stuff about the file upload
497 $timemessage = 4;
499 $message .= '<br />'.get_string("postupdated", "forum");
501 if ($subscribemessage = forum_post_subscription($fromform)) {
502 $timemessage = 4;
504 if ($forum->type == 'single') {
505 // Single discussion forums are an exception. We show
506 // the forum itself since it only has one discussion
507 // thread.
508 $discussionurl = "view.php?f=$forum->id";
509 } else {
510 $discussionurl = "discuss.php?d=$discussion->id#p$fromform->id";
512 add_to_log($course->id, "forum", "update post",
513 "$discussionurl&amp;parent=$fromform->id", "$fromform->id", $cm->id);
515 redirect(forum_go_back_to("$discussionurl"), $message.$subscribemessage, $timemessage);
517 exit;
520 } else if ($fromform->discussion) { // Adding a new post to an existing discussion
521 $message = '';
522 $addpost=$fromform;
523 $addpost->forum=$forum->id;
524 if ($fromform->id = forum_add_new_post($addpost, $message)) {
526 $timemessage = 2;
527 if (!empty($message)) { // if we're printing stuff about the file upload
528 $timemessage = 4;
531 if ($subscribemessage = forum_post_subscription($fromform)) {
532 $timemessage = 4;
535 if (!empty($fromform->mailnow)) {
536 $message .= get_string("postmailnow", "forum");
537 $timemessage = 4;
538 } else {
539 $message .= '<br />'.get_string("postadded", "forum", format_time($CFG->maxeditingtime));
542 if ($forum->type == 'single') {
543 // Single discussion forums are an exception. We show
544 // the forum itself since it only has one discussion
545 // thread.
546 $discussionurl = "view.php?f=$forum->id";
547 } else {
548 $discussionurl = "discuss.php?d=$discussion->id";
550 add_to_log($course->id, "forum", "add post",
551 "$discussionurl&amp;parent=$fromform->id", "$fromform->id", $cm->id);
553 redirect(forum_go_back_to("$discussionurl#p$fromform->id"), $message.$subscribemessage, $timemessage);
555 } else {
556 error(get_string("couldnotadd", "forum"), $errordestination);
558 exit;
560 } else { // Adding a new discussion
561 $fromform->mailnow = empty($fromform->mailnow) ? 0 : 1;
562 $discussion = $fromform;
563 $discussion->name = $fromform->subject;
564 $discussion->intro = $fromform->message;
565 $newstopic = false;
567 if ($forum->type == 'news' && !$fromform->parent) {
568 $newstopic = true;
570 $discussion->timestart = $fromform->timestart;
571 $discussion->timeend = $fromform->timeend;
573 $message = '';
574 if ($discussion->id = forum_add_discussion($discussion, $message)) {
576 add_to_log($course->id, "forum", "add discussion",
577 "discuss.php?d=$discussion->id", "$discussion->id", $cm->id);
579 $timemessage = 2;
580 if (!empty($message)) { // if we're printing stuff about the file upload
581 $timemessage = 4;
584 if ($fromform->mailnow) {
585 $message .= get_string("postmailnow", "forum");
586 $timemessage = 4;
587 } else {
588 $message .= '<br />'.get_string("postadded", "forum", format_time($CFG->maxeditingtime));
591 if ($subscribemessage = forum_post_subscription($discussion)) {
592 $timemessage = 4;
595 redirect(forum_go_back_to("view.php?f=$fromform->forum"), $message.$subscribemessage, $timemessage);
597 } else {
598 error(get_string("couldnotadd", "forum"), $errordestination);
601 exit;
607 // To get here they need to edit a post, and the $post
608 // variable will be loaded with all the particulars,
609 // so bring up the form.
611 // $course, $forum are defined. $discussion is for edit and reply only.
613 $cm = get_coursemodule_from_instance("forum", $forum->id, $course->id);
615 require_login($course->id, false, $cm);
617 $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
619 if ($post->discussion) {
620 if (! $toppost = get_record("forum_posts", "discussion", $post->discussion, "parent", 0)) {
621 error("Could not find top parent of post $post->id");
623 } else {
624 $toppost->subject = ($forum->type == "news") ? get_string("addanewtopic", "forum") :
625 get_string("addanewdiscussion", "forum");
628 $strforums = get_string("modulenameplural", "forum");
631 $crumbs[] = array('name' => $strforums, 'link' => "../forum/index.php?id=$course->id", 'type' => 'activity');
632 $crumbs[] = array('name' => $forum->name, 'link' => "view.php?f=$forum->id", 'type' => 'activityinstance');
635 if ($post->parent) {
636 $crumbs[] = array('name' => format_string($toppost->subject, true), 'link' => "discuss.php?d=$discussion->id", 'type' => 'activityinstance');
637 $crumbs[] = array('name' => get_string('editing', 'forum'), 'link' => '', 'type' => 'action');
638 } else {
639 $crumbs[] = array('name' => format_string($toppost->subject), 'link' => '', 'type' => 'action');
642 if (empty($post->edit)) {
643 $post->edit = '';
647 if (empty($discussion->name)) {
648 if (empty($discussion)) {
649 $discussion = new object;
651 $discussion->name = $forum->name;
653 if ($forum->type == 'single') {
654 // There is only one discussion thread for this forum type. We should
655 // not show the discussion name (same as forum name in this case) in
656 // the breadcrumbs.
657 $strdiscussionname = '';
658 $navtail = '';
659 } else {
660 // Show the discussion name in the breadcrumbs.
661 $strdiscussionname = format_string($discussion->name).':';
664 $forcefocus = empty($reply) ? NULL : 'message';
667 $navigation = build_navigation($crumbs);
669 print_header("$course->shortname: $strdiscussionname ".
670 format_string($toppost->subject), $course->fullname,
671 $navigation, $mform_post->focus($forcefocus), "", true, "", navmenu($course, $cm));
674 // checkup
675 if (!empty($parent) && !forum_user_can_see_post($forum, $discussion, $post)) {
676 error("You cannot reply to this post");
678 if (empty($parent) && empty($edit) && !forum_user_can_post_discussion($forum)) {
679 error("You cannot start a new discussion in this forum");
682 if ($forum->type == 'qanda'
683 && !has_capability('mod/forum:viewqandawithoutposting', $modcontext)
684 && !empty($discussion->id)
685 && !forum_user_has_posted($forum->id, $discussion->id, $USER->id)) {
686 notify(get_string('qandanotify','forum'));
689 forum_check_throttling($forum);
691 if (!empty($parent)) {
692 forum_print_post($parent, $course->id, $ownpost=false, $reply=false, $link=false);
693 if (empty($post->edit)) {
694 if (forum_tp_can_track_forums($forum) && forum_tp_is_tracked($forum)) {
695 $user_read_array = forum_tp_get_discussion_read_records($USER->id, $discussion->id);
696 } else {
697 $user_read_array = array();
699 if ($forum->type != 'qanda' || forum_user_can_see_discussion($forum, $discussion, $modcontext)) {
700 forum_print_posts_threaded($parent->id, $course->id, 0, false, false, $user_read_array, $discussion->forum);
703 $heading = get_string("yourreply", "forum");
704 } else {
705 $forum->intro = trim($forum->intro);
706 if (!empty($forum->intro)) {
707 print_box(format_text($forum->intro), 'generalbox', 'intro');
709 if ($forum->type == 'qanda') {
710 $heading = get_string('yournewquestion', 'forum');
711 } else {
712 $heading = get_string('yournewtopic', 'forum');
716 if ($USER->id != $post->userid) { // Not the original author, so add a message to the end
717 $data->date = userdate($post->modified);
718 if ($post->format == FORMAT_HTML) {
719 $data->name = '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$USER->id.'&course='.$post->course.'">'.
720 fullname($USER).'</a>';
721 $post->message .= '<p>(<span class="edited">'.get_string('editedby', 'forum', $data).'</span>)</p>';
722 } else {
723 $data->name = fullname($USER);
724 $post->message .= "\n\n(".get_string('editedby', 'forum', $data).')';
728 //load data into form
729 $subscribe=(isset($post->forum)&&forum_is_subscribed($USER->id, $post->forum)) ||
730 (!empty($USER->autosubscribe));
733 $mform_post->set_data(array( 'general'=>$heading,
734 'subject'=>$post->subject,
735 'message'=>$post->message,
736 'subscribe'=>$subscribe?1:0,
737 'mailnow'=>!empty($post->mailnow),
738 'userid'=>$post->userid,
739 'parent'=>$post->parent,
740 'discussion'=>$post->discussion,
741 'course'=>$course->id)+
743 $page_params+
745 (isset($post->format)?array(
746 'format'=>$post->format):
747 array())+
749 (isset($dicussion->timestart)?array(
750 'timestart'=>$discussion->timestart):
751 array())+
753 (isset($discussion->timeend)?array(
754 'timeend'=>$discussion->timeend):
755 array())+
757 (isset($post->groupid)?array(
758 'groupid'=>$post->groupid):
759 array())+
761 (isset($discussion->id)?
762 array('discussion'=>$discussion->id):
763 array()));
766 $mform_post->display();
769 print_footer($course);