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
);
16 $groupid = optional_param('groupid', null, PARAM_INT
);
19 //these page_params will be passed as hidden variables later in the form.
20 $page_params = array('reply'=>$reply, 'forum'=>$forum, 'edit'=>$edit);
22 $sitecontext = get_context_instance(CONTEXT_SYSTEM
);
24 if (has_capability('moodle/legacy:guest', $sitecontext, NULL, false)) {
26 $wwwroot = $CFG->wwwroot
.'/login/index.php';
27 if (!empty($CFG->loginhttps
)) {
28 $wwwroot = str_replace('http:', 'https:', $wwwroot);
31 if (!empty($forum)) { // User is starting a new discussion in a forum
32 if (! $forum = get_record('forum', 'id', $forum)) {
33 error('The forum number was incorrect');
35 } else if (!empty($reply)) { // User is writing a new reply
36 if (! $parent = forum_get_post_full($reply)) {
37 error('Parent post ID was incorrect');
39 if (! $discussion = get_record('forum_discussions', 'id', $parent->discussion
)) {
40 error('This post is not part of a discussion!');
42 if (! $forum = get_record('forum', 'id', $discussion->forum
)) {
43 error('The forum number was incorrect');
46 if (! $course = get_record('course', 'id', $forum->course
)) {
47 error('The course number was incorrect');
50 if (!$cm = get_coursemodule_from_instance('forum', $forum->id
, $course->id
)) { // For the logs
51 error('Could not get the course module for the forum instance.');
53 $modcontext = get_context_instance(CONTEXT_MODULE
, $cm->id
);
56 if (!get_referer()) { // No referer - probably coming in via email See MDL-9052
60 $navigation = build_navigation('', $cm);
61 print_header($course->shortname
, $course->fullname
, $navigation, '' , '', true, "", navmenu($course, $cm));
63 notice_yesno(get_string('noguestpost', 'forum').'<br /><br />'.get_string('liketologin'),
64 $wwwroot, get_referer(false));
65 print_footer($course);
69 require_login(0, false); // Script is useless unless they're logged in
71 if (!empty($forum)) { // User is starting a new discussion in a forum
72 if (! $forum = get_record("forum", "id", $forum)) {
73 error("The forum number was incorrect ($forum)");
75 if (! $course = get_record("course", "id", $forum->course
)) {
76 error("The course number was incorrect ($forum->course)");
78 if (! $cm = get_coursemodule_from_instance("forum", $forum->id
, $course->id
)) {
79 error("Incorrect course module");
82 $coursecontext = get_context_instance(CONTEXT_COURSE
, $course->id
);
84 if (! forum_user_can_post_discussion($forum, $groupid, -1, $cm)) {
85 if (has_capability('moodle/legacy:guest', $coursecontext, NULL, false)) { // User is a guest here!
86 $SESSION->wantsurl
= $FULLME;
87 $SESSION->enrolcancel
= $_SERVER['HTTP_REFERER'];
88 redirect($CFG->wwwroot
.'/course/enrol.php?id='.$course->id
, get_string('youneedtoenrol'));
90 print_error('nopostforum', 'forum');
94 if (!$cm->visible
and !has_capability('moodle/course:viewhiddenactivities', $coursecontext)) {
95 print_error("activityiscurrentlyhidden");
98 if (isset($_SERVER["HTTP_REFERER"])) {
99 $SESSION->fromurl
= $_SERVER["HTTP_REFERER"];
101 $SESSION->fromurl
= '';
105 // Load up the $post variable.
107 $post = new object();
108 $post->course
= $course->id
;
109 $post->forum
= $forum->id
;
110 $post->discussion
= 0; // ie discussion # not defined yet
113 $post->userid
= $USER->id
;
116 if (isset($groupid)) {
117 $post->groupid
= $groupid;
119 $post->groupid
= groups_get_activity_group($cm);
124 } else if (!empty($reply)) { // User is writing a new reply
126 if (! $parent = forum_get_post_full($reply)) {
127 error("Parent post ID was incorrect");
129 if (! $discussion = get_record("forum_discussions", "id", $parent->discussion
)) {
130 error("This post is not part of a discussion!");
132 if (! $forum = get_record("forum", "id", $discussion->forum
)) {
133 error("The forum number was incorrect ($discussion->forum)");
135 if (! $course = get_record("course", "id", $discussion->course
)) {
136 error("The course number was incorrect ($discussion->course)");
138 if (! $cm = get_coursemodule_from_instance("forum", $forum->id
, $course->id
)) {
139 error("Incorrect cm");
142 $coursecontext = get_context_instance(CONTEXT_COURSE
, $course->id
);
143 $modcontext = get_context_instance(CONTEXT_MODULE
, $cm->id
);
145 if (! forum_user_can_post($forum, $discussion, $USER, $cm, $course, $modcontext)) {
146 if (has_capability('moodle/legacy:guest', $coursecontext, NULL, false)) { // User is a guest here!
147 $SESSION->wantsurl
= $FULLME;
148 $SESSION->enrolcancel
= $_SERVER['HTTP_REFERER'];
149 redirect($CFG->wwwroot
.'/course/enrol.php?id='.$course->id
, get_string('youneedtoenrol'));
151 print_error('nopostforum', 'forum');
155 // Make sure user can post here
156 if (groupmode($course, $cm) == SEPARATEGROUPS
and !has_capability('moodle/site:accessallgroups', $modcontext)) {
157 if ($discussion->groupid
== -1) {
158 print_error('nopostforum', 'forum');
160 if (!groups_is_member($discussion->groupid
)) {
161 print_error('nopostforum', 'forum');
166 if (!$cm->visible
and !has_capability('moodle/course:viewhiddenactivities', $coursecontext)) {
167 print_error("activityiscurrentlyhidden");
170 // Load up the $post variable.
172 $post = new object();
173 $post->course
= $course->id
;
174 $post->forum
= $forum->id
;
175 $post->discussion
= $parent->discussion
;
176 $post->parent
= $parent->id
;
177 $post->subject
= $parent->subject
;
178 $post->userid
= $USER->id
;
181 $post->groupid
= ($discussion->groupid
== -1) ?
0 : $discussion->groupid
;
183 $strre = get_string('re', 'forum');
184 if (!(substr($post->subject
, 0, strlen($strre)) == $strre)) {
185 $post->subject
= $strre.' '.$post->subject
;
188 unset($SESSION->fromdiscussion
);
190 } else if (!empty($edit)) { // User is editing their own post
192 if (! $post = forum_get_post_full($edit)) {
193 error("Post ID was incorrect");
196 if (! $parent = forum_get_post_full($post->parent
)) {
197 error("Parent post ID was incorrect ($post->parent)");
201 if (! $discussion = get_record("forum_discussions", "id", $post->discussion
)) {
202 error("This post is not part of a discussion! ($edit)");
204 if (! $forum = get_record("forum", "id", $discussion->forum
)) {
205 error("The forum number was incorrect ($discussion->forum)");
207 if (! $course = get_record("course", "id", $discussion->course
)) {
208 error("The course number was incorrect ($discussion->course)");
210 if (!$cm = get_coursemodule_from_instance("forum", $forum->id
, $course->id
)) {
211 error('Could not get the course module for the forum instance.');
213 $modcontext = get_context_instance(CONTEXT_MODULE
, $cm->id
);
215 if (!($forum->type
== 'news' && !$post->parent
&& $discussion->timestart
> time())) {
216 if (((time() - $post->created
) > $CFG->maxeditingtime
) and
217 !has_capability('mod/forum:editanypost', $modcontext)) {
218 error( get_string("maxtimehaspassed", "forum", format_time($CFG->maxeditingtime
)) );
221 if (($post->userid
<> $USER->id
) and
222 !has_capability('mod/forum:editanypost', $modcontext)) {
223 error("You can't edit other people's posts!");
227 // Load up the $post variable.
229 $post->course
= $course->id
;
230 $post->forum
= $forum->id
;
231 $post->groupid
= ($discussion->groupid
== -1) ?
0 : $discussion->groupid
;
233 trusttext_prepare_edit($post->message
, $post->format
, can_use_html_editor(), $modcontext);
235 unset($SESSION->fromdiscussion
);
238 }else if (!empty($delete)) { // User is deleting a post
240 if (! $post = forum_get_post_full($delete)) {
241 error("Post ID was incorrect");
243 if (! $discussion = get_record("forum_discussions", "id", $post->discussion
)) {
244 error("This post is not part of a discussion!");
246 if (! $forum = get_record("forum", "id", $discussion->forum
)) {
247 error("The forum number was incorrect ($discussion->forum)");
249 if (!$cm = get_coursemodule_from_instance("forum", $forum->id
, $forum->course
)) {
250 error('Could not get the course module for the forum instance.');
252 if (!$course = get_record('course', 'id', $forum->course
)) {
253 error('Incorrect course');
256 require_login($course, false, $cm);
257 $modcontext = get_context_instance(CONTEXT_MODULE
, $cm->id
);
259 if ( !(($post->userid
== $USER->id
&& has_capability('mod/forum:deleteownpost', $modcontext))
260 ||
has_capability('mod/forum:deleteanypost', $modcontext)) ) {
261 error("You can't delete this post!");
265 $replycount = forum_count_replies($post);
267 if (!empty($confirm)) { // User has confirmed the delete
269 if ($post->totalscore
) {
270 notice(get_string("couldnotdeleteratings", "forum"),
271 forum_go_back_to("discuss.php?d=$post->discussion"));
273 } else if ($replycount && !has_capability('mod/forum:deleteanypost', $modcontext)) {
274 print_error("couldnotdeletereplies", "forum",
275 forum_go_back_to("discuss.php?d=$post->discussion"));
278 if (! $post->parent
) { // post is a discussion topic as well, so delete discussion
279 if ($forum->type
== 'single') {
280 notice("Sorry, but you are not allowed to delete that discussion!",
281 forum_go_back_to("discuss.php?d=$post->discussion"));
283 forum_delete_discussion($discussion);
285 add_to_log($discussion->course
, "forum", "delete discussion",
286 "view.php?id=$cm->id", "$forum->id", $cm->id
);
288 redirect("view.php?f=$discussion->forum");
290 } else if (forum_delete_post($post, has_capability('mod/forum:deleteanypost', $modcontext))) {
292 if ($forum->type
== 'single') {
293 // Single discussion forums are an exception. We show
294 // the forum itself since it only has one discussion
296 $discussionurl = "view.php?f=$forum->id";
298 $discussionurl = "discuss.php?d=$post->discussion";
301 add_to_log($discussion->course
, "forum", "delete post", $discussionurl, "$post->id", $cm->id
);
303 redirect(forum_go_back_to($discussionurl));
305 error("An error occurred while deleting record $post->id");
310 } else { // User just asked to delete something
315 if (!has_capability('mod/forum:deleteanypost', $modcontext)) {
316 print_error("couldnotdeletereplies", "forum",
317 forum_go_back_to("discuss.php?d=$post->discussion"));
320 notice_yesno(get_string("deletesureplural", "forum", $replycount+
1),
321 "post.php?delete=$delete&confirm=$delete",
322 $CFG->wwwroot
.'/mod/forum/discuss.php?d='.$post->discussion
.'#p'.$post->id
);
324 forum_print_post($post, $discussion, $forum, $cm, $course, false, false, false);
326 if (empty($post->edit
)) {
327 $forumtracked = forum_tp_is_tracked($forum);
328 $posts = forum_get_all_discussion_posts($discussion->id
, "created ASC", $forumtracked);
329 forum_print_posts_nested($course, $cm, $forum, $discussion, $post, false, false, $forumtracked, $posts);
333 notice_yesno(get_string("deletesure", "forum", $replycount),
334 "post.php?delete=$delete&confirm=$delete",
335 $CFG->wwwroot
.'/mod/forum/discuss.php?d='.$post->discussion
.'#p'.$post->id
);
336 forum_print_post($post, $discussion, $forum, $cm, $course, false, false, false);
340 print_footer($course);
344 } else if (!empty($prune)) { // Pruning
346 if (!$post = forum_get_post_full($prune)) {
347 error("Post ID was incorrect");
349 if (!$discussion = get_record("forum_discussions", "id", $post->discussion
)) {
350 error("This post is not part of a discussion!");
352 if (!$forum = get_record("forum", "id", $discussion->forum
)) {
353 error("The forum number was incorrect ($discussion->forum)");
355 if ($forum->type
== 'single') {
356 error('Discussions from this forum cannot be split');
358 if (!$post->parent
) {
359 error('This is already the first post in the discussion');
361 if (!$cm = get_coursemodule_from_instance("forum", $forum->id
, $forum->course
)) { // For the logs
362 error('Could not get the course module for the forum instance.');
364 $modcontext = get_context_instance(CONTEXT_MODULE
, $cm->id
);
366 if (!has_capability('mod/forum:splitdiscussions', $modcontext)) {
367 error("You can't split discussions!");
370 if (!empty($name)) { // User has confirmed the prune
372 $newdiscussion = new object();
373 $newdiscussion->course
= $discussion->course
;
374 $newdiscussion->forum
= $discussion->forum
;
375 $newdiscussion->name
= $name;
376 $newdiscussion->firstpost
= $post->id
;
377 $newdiscussion->userid
= $discussion->userid
;
378 $newdiscussion->groupid
= $discussion->groupid
;
379 $newdiscussion->assessed
= $discussion->assessed
;
380 $newdiscussion->usermodified
= $post->userid
;
381 $newdiscussion->timestart
= $discussion->timestart
;
382 $newdiscussion->timeend
= $discussion->timeend
;
384 if (!$newid = insert_record('forum_discussions', $newdiscussion)) {
385 error('Could not create new discussion');
388 $newpost = new object();
389 $newpost->id
= $post->id
;
390 $newpost->parent
= 0;
391 $newpost->subject
= $name;
393 if (!update_record("forum_posts", $newpost)) {
394 error('Could not update the original post');
397 forum_change_discussionid($post->id
, $newid);
399 // update last post in each discussion
400 forum_discussion_update_last_post($discussion->id
);
401 forum_discussion_update_last_post($newid);
403 add_to_log($discussion->course
, "forum", "prune post",
404 "discuss.php?d=$newid", "$post->id", $cm->id
);
406 redirect(forum_go_back_to("discuss.php?d=$newid"));
408 } else { // User just asked to prune something
410 $course = get_record('course', 'id', $forum->course
);
413 $navlinks[] = array('name' => format_string($post->subject
, true), 'link' => "discuss.php?d=$discussion->id", 'type' => 'title');
414 $navlinks[] = array('name' => get_string("prune", "forum"), 'link' => '', 'type' => 'title');
415 $navigation = build_navigation($navlinks, $cm);
416 print_header_simple(format_string($discussion->name
).": ".format_string($post->subject
), "", $navigation, '', "", true, "", navmenu($course, $cm));
418 print_heading(get_string('pruneheading', 'forum'));
421 include('prune.html');
423 forum_print_post($post, $discussion, $forum, $cm, $course, false, false, false);
426 print_footer($course);
429 error("No operation specified");
433 if (!isset($coursecontext)) {
434 // Has not yet been set by post.php.
435 $coursecontext = get_context_instance(CONTEXT_COURSE
, $forum->course
);
438 if (!$cm = get_coursemodule_from_instance('forum', $forum->id
, $course->id
)) { // For the logs
439 error('Could not get the course module for the forum instance.');
441 $modcontext = get_context_instance(CONTEXT_MODULE
, $cm->id
);
443 $mform_post = new mod_forum_post_form('post.php', array('course'=>$course, 'cm'=>$cm, 'coursecontext'=>$coursecontext, 'modcontext'=>$modcontext, 'forum'=>$forum, 'post'=>$post));
445 if ($fromform = $mform_post->get_data()) {
448 require_login($course, false, $cm);
450 if (empty($SESSION->fromurl
)) {
451 $errordestination = "$CFG->wwwroot/mod/forum/view.php?f=$forum->id";
453 $errordestination = $SESSION->fromurl
;
456 // TODO add attachment processing
457 //$fromform->attachment = isset($_FILES['attachment']) ? $_FILES['attachment'] : NULL;
459 trusttext_after_edit($fromform->message
, $modcontext);
461 if ($fromform->edit
) { // Updating a post
462 unset($fromform->groupid
);
463 $fromform->id
= $fromform->edit
;
467 if (!$realpost = get_record('forum_posts', 'id', $fromform->id
)) {
468 $realpost = new object;
469 $realpost->userid
= -1;
473 // if user has edit any post capability
474 // or has either startnewdiscussion or reply capability and is editting own post
475 // then he can proceed
477 if ( !(($realpost->userid
== $USER->id
&& (has_capability('mod/forum:replypost', $modcontext)
478 ||
has_capability('mod/forum:startdiscussion', $modcontext))) ||
479 has_capability('mod/forum:editanypost', $modcontext)) ) {
480 error("You can not update this post");
483 $updatepost = $fromform; //realpost
484 $updatepost->forum
= $forum->id
;
485 if (!forum_update_post($updatepost, $message)) {
486 print_error("couldnotupdate", "forum", $errordestination);
490 if (($forum->type
== 'single') && ($updatepost->parent
== '0')){ // updating first post of single discussion type -> updating forum intro
491 $forum->intro
= $updatepost->message
;
492 $forum->timemodified
= time();
493 if (!update_record("forum", $forum)) {
494 print_error("couldnotupdate", "forum", $errordestination);
499 if (!empty($message)) { // if we're printing stuff about the file upload
502 $message .= '<br />'.get_string("postupdated", "forum");
504 if ($subscribemessage = forum_post_subscription($fromform)) {
507 if ($forum->type
== 'single') {
508 // Single discussion forums are an exception. We show
509 // the forum itself since it only has one discussion
511 $discussionurl = "view.php?f=$forum->id";
513 $discussionurl = "discuss.php?d=$discussion->id#p$fromform->id";
515 add_to_log($course->id
, "forum", "update post",
516 "$discussionurl&parent=$fromform->id", "$fromform->id", $cm->id
);
518 redirect(forum_go_back_to("$discussionurl"), $message.$subscribemessage, $timemessage);
523 } else if ($fromform->discussion
) { // Adding a new post to an existing discussion
524 unset($fromform->groupid
);
527 $addpost->forum
=$forum->id
;
528 if ($fromform->id
= forum_add_new_post($addpost, $message)) {
531 if (!empty($message)) { // if we're printing stuff about the file upload
535 if ($subscribemessage = forum_post_subscription($fromform)) {
539 if (!empty($fromform->mailnow
)) {
540 $message .= get_string("postmailnow", "forum");
543 $message .= '<p>'.get_string("postaddedsuccess", "forum") . '</p>';
544 $message .= '<p>'.get_string("postaddedtimeleft", "forum", format_time($CFG->maxeditingtime
)) . '</p>';
547 if ($forum->type
== 'single') {
548 // Single discussion forums are an exception. We show
549 // the forum itself since it only has one discussion
551 $discussionurl = "view.php?f=$forum->id";
553 $discussionurl = "discuss.php?d=$discussion->id";
555 add_to_log($course->id
, "forum", "add post",
556 "$discussionurl&parent=$fromform->id", "$fromform->id", $cm->id
);
558 redirect(forum_go_back_to("$discussionurl#p$fromform->id"), $message.$subscribemessage, $timemessage);
561 print_error("couldnotadd", "forum", $errordestination);
565 } else { // Adding a new discussion
566 if (!forum_user_can_post_discussion($forum, $fromform->groupid
, -1, $cm, $modcontext)) {
567 error('Can not add discussion, sorry.');
569 if (empty($fromform->groupid
)) {
570 $fromform->groupid
= -1;
573 $fromform->mailnow
= empty($fromform->mailnow
) ?
0 : 1;
574 $discussion = $fromform;
575 $discussion->name
= $fromform->subject
;
576 $discussion->intro
= $fromform->message
;
579 if ($forum->type
== 'news' && !$fromform->parent
) {
582 $discussion->timestart
= $fromform->timestart
;
583 $discussion->timeend
= $fromform->timeend
;
586 if ($discussion->id
= forum_add_discussion($discussion, $message)) {
588 add_to_log($course->id
, "forum", "add discussion",
589 "discuss.php?d=$discussion->id", "$discussion->id", $cm->id
);
592 if (!empty($message)) { // if we're printing stuff about the file upload
596 if ($fromform->mailnow
) {
597 $message .= get_string("postmailnow", "forum");
600 $message .= '<p>'.get_string("postaddedsuccess", "forum") . '</p>';
601 $message .= '<p>'.get_string("postaddedtimeleft", "forum", format_time($CFG->maxeditingtime
)) . '</p>';
604 if ($subscribemessage = forum_post_subscription($discussion)) {
608 redirect(forum_go_back_to("view.php?f=$fromform->forum"), $message.$subscribemessage, $timemessage);
611 print_error("couldnotadd", "forum", $errordestination);
620 // To get here they need to edit a post, and the $post
621 // variable will be loaded with all the particulars,
622 // so bring up the form.
624 // $course, $forum are defined. $discussion is for edit and reply only.
626 $cm = get_coursemodule_from_instance("forum", $forum->id
, $course->id
);
628 require_login($course->id
, false, $cm);
630 $modcontext = get_context_instance(CONTEXT_MODULE
, $cm->id
);
632 if ($post->discussion
) {
633 if (! $toppost = get_record("forum_posts", "discussion", $post->discussion
, "parent", 0)) {
634 error("Could not find top parent of post $post->id");
637 $toppost->subject
= ($forum->type
== "news") ?
get_string("addanewtopic", "forum") :
638 get_string("addanewdiscussion", "forum");
641 if (empty($post->edit
)) {
645 if (empty($discussion->name
)) {
646 if (empty($discussion)) {
647 $discussion = new object;
649 $discussion->name
= $forum->name
;
651 if ($forum->type
== 'single') {
652 // There is only one discussion thread for this forum type. We should
653 // not show the discussion name (same as forum name in this case) in
655 $strdiscussionname = '';
657 // Show the discussion name in the breadcrumbs.
658 $strdiscussionname = format_string($discussion->name
).':';
661 $forcefocus = empty($reply) ?
NULL : 'message';
665 $navlinks[] = array('name' => format_string($toppost->subject
, true), 'link' => "discuss.php?d=$discussion->id", 'type' => 'title');
666 $navlinks[] = array('name' => get_string('editing', 'forum'), 'link' => '', 'type' => 'title');
668 $navlinks[] = array('name' => format_string($toppost->subject
), 'link' => '', 'type' => 'title');
670 $navigation = build_navigation($navlinks, $cm);
672 print_header("$course->shortname: $strdiscussionname ".
673 format_string($toppost->subject
), $course->fullname
,
674 $navigation, $mform_post->focus($forcefocus), "", true, "", navmenu($course, $cm));
677 if (!empty($parent) && !forum_user_can_see_post($forum, $discussion, $post, null, $cm)) {
678 error("You cannot reply to this post");
680 if (empty($parent) && empty($edit) && !forum_user_can_post_discussion($forum, $groupid, -1, $cm, $modcontext)) {
681 error("You cannot start a new discussion in this forum");
684 if ($forum->type
== 'qanda'
685 && !has_capability('mod/forum:viewqandawithoutposting', $modcontext)
686 && !empty($discussion->id
)
687 && !forum_user_has_posted($forum->id
, $discussion->id
, $USER->id
)) {
688 notify(get_string('qandanotify','forum'));
691 forum_check_throttling($forum, $cm);
693 if (!empty($parent)) {
694 if (! $discussion = get_record('forum_discussions', 'id', $parent->discussion
)) {
695 error('This post is not part of a discussion!');
698 forum_print_post($parent, $discussion, $forum, $cm, $course, false, false, false);
699 if (empty($post->edit
)) {
700 if ($forum->type
!= 'qanda' ||
forum_user_can_see_discussion($forum, $discussion, $modcontext)) {
701 $forumtracked = forum_tp_is_tracked($forum);
702 $posts = forum_get_all_discussion_posts($discussion->id
, "created ASC", $forumtracked);
703 forum_print_posts_threaded($course, $cm, $forum, $discussion, $parent, 0, false, false, $forumtracked, $posts);
706 $heading = get_string("yourreply", "forum");
708 $forum->intro
= trim($forum->intro
);
709 if (!empty($forum->intro
)) {
710 print_box(format_text($forum->intro
), 'generalbox', 'intro');
712 if ($forum->type
== 'qanda') {
713 $heading = get_string('yournewquestion', 'forum');
715 $heading = get_string('yournewtopic', 'forum');
719 if ($USER->id
!= $post->userid
) { // Not the original author, so add a message to the end
720 $data->date
= userdate($post->modified
);
721 if ($post->format
== FORMAT_HTML
) {
722 $data->name
= '<a href="'.$CFG->wwwroot
.'/user/view.php?id='.$USER->id
.'&course='.$post->course
.'">'.
723 fullname($USER).'</a>';
724 $post->message
.= '<p>(<span class="edited">'.get_string('editedby', 'forum', $data).'</span>)</p>';
726 $data->name
= fullname($USER);
727 $post->message
.= "\n\n(".get_string('editedby', 'forum', $data).')';
731 //load data into form
733 if (forum_is_subscribed($USER->id
, $forum->id
)) {
736 } else if (forum_user_has_posted($forum->id
, 0, $USER->id
)) {
740 // user not posted yet - use subscription default specified in profile
741 $subscribe = !empty($USER->autosubscribe
);
744 // HACK ALERT: this is very wrong, the defaults should be always initialized before calling $mform->get_data() !!!
745 $mform_post->set_data(array( 'general'=>$heading,
746 'subject'=>$post->subject
,
747 'message'=>$post->message
,
748 'subscribe'=>$subscribe?
1:0,
749 'mailnow'=>!empty($post->mailnow
),
750 'userid'=>$post->userid
,
751 'parent'=>$post->parent
,
752 'discussion'=>$post->discussion
,
753 'course'=>$course->id
)+
757 (isset($post->format
)?
array(
758 'format'=>$post->format
):
761 (isset($discussion->timestart
)?
array(
762 'timestart'=>$discussion->timestart
):
765 (isset($discussion->timeend
)?
array(
766 'timeend'=>$discussion->timeend
):
769 (isset($post->groupid
)?
array(
770 'groupid'=>$post->groupid
):
773 (isset($discussion->id
)?
774 array('discussion'=>$discussion->id
):
778 $mform_post->display();
781 print_footer($course);