2004-09-12 16:24:41 +00:00
|
|
|
<?php // $Id$
|
2002-07-31 14:19:35 +00:00
|
|
|
|
|
|
|
// Edit and save a new post to a discussion
|
|
|
|
|
2005-04-26 20:39:08 +00:00
|
|
|
require_once('../../config.php');
|
|
|
|
require_once('lib.php');
|
|
|
|
|
|
|
|
$reply = optional_param('reply', 0, PARAM_INT);
|
2005-06-10 19:54:41 +00:00
|
|
|
$forum = optional_param('forum', 0, PARAM_INT);
|
|
|
|
$edit = optional_param('edit', 0, PARAM_INT);
|
|
|
|
$delete = optional_param('delete', 0, PARAM_INT);
|
|
|
|
$prune = optional_param('prune',0,PARAM_INT);
|
|
|
|
$name = optional_param('name','',PARAM_CLEAN);
|
|
|
|
$confirm = optional_param('confirm',0,PARAM_INT);
|
2006-08-08 05:13:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2002-07-31 14:19:35 +00:00
|
|
|
if (isguest()) {
|
2005-03-06 06:20:37 +00:00
|
|
|
$wwwroot = $CFG->wwwroot.'/login/index.php';
|
|
|
|
if (!empty($CFG->loginhttps)) {
|
2006-08-08 05:13:06 +00:00
|
|
|
$wwwroot = str_replace('http','https', $wwwroot);
|
2005-03-06 06:20:37 +00:00
|
|
|
}
|
2005-03-06 06:48:48 +00:00
|
|
|
|
2006-08-08 05:13:06 +00:00
|
|
|
if (isset($forum)) { // User is starting a new discussion in a forum
|
2005-03-06 06:48:48 +00:00
|
|
|
if (! $forum = get_record('forum', 'id', $forum)) {
|
|
|
|
error('The forum number was incorrect');
|
|
|
|
}
|
2005-04-26 20:39:08 +00:00
|
|
|
} else if (!empty($reply)) { // User is writing a new reply
|
2005-03-06 06:48:48 +00:00
|
|
|
if (! $parent = forum_get_post_full($reply)) {
|
|
|
|
error('Parent post ID was incorrect');
|
|
|
|
}
|
|
|
|
if (! $discussion = get_record('forum_discussions', 'id', $parent->discussion)) {
|
|
|
|
error('This post is not part of a discussion!');
|
|
|
|
}
|
|
|
|
if (! $forum = get_record('forum', 'id', $discussion->forum)) {
|
|
|
|
error('The forum number was incorrect');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (! $course = get_record('course', 'id', $forum->course)) {
|
|
|
|
error('The course number was incorrect');
|
|
|
|
}
|
2006-08-16 03:24:43 +00:00
|
|
|
|
2005-03-06 06:48:48 +00:00
|
|
|
if (!$cm = get_coursemodule_from_instance('forum', $forum->id, $course->id)) { // For the logs
|
2006-08-08 05:13:06 +00:00
|
|
|
// Teacher forum?
|
2005-03-06 06:48:48 +00:00
|
|
|
$cm->id = 0;
|
2006-08-08 05:13:06 +00:00
|
|
|
} else {
|
|
|
|
$modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
|
2005-03-06 06:48:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$strforums = get_string('modulenameplural', 'forum');
|
|
|
|
if ($course->category) {
|
|
|
|
print_header($course->shortname, $course->fullname,
|
|
|
|
"<a href=\"../../course/view.php?id=$course->id\">$course->shortname</a> ->
|
2005-03-13 09:56:10 +00:00
|
|
|
<a href=\"../forum/index.php?id=$course->id\">$strforums</a> ->
|
2005-03-26 01:57:40 +00:00
|
|
|
<a href=\"view.php?f=$forum->id\">".format_string($forum->name,true)."</a>", '', '', true, "", navmenu($course, $cm));
|
2005-03-06 06:48:48 +00:00
|
|
|
} else {
|
|
|
|
print_header($course->shortname, $course->fullname,
|
2005-03-13 09:56:10 +00:00
|
|
|
"<a href=\"../forum/index.php?id=$course->id\">$strforums</a> ->
|
2005-03-26 01:57:40 +00:00
|
|
|
<a href=\"view.php?f=$forum->id\">".format_string($forum->name)."</a>", '', '', true, "", navmenu($course, $cm));
|
2005-03-06 06:48:48 +00:00
|
|
|
}
|
2005-03-06 06:20:37 +00:00
|
|
|
notice_yesno(get_string('noguestpost', 'forum').'<br /><br />'.get_string('liketologin'),
|
|
|
|
$wwwroot, $_SERVER['HTTP_REFERER']);
|
2005-03-17 15:12:07 +00:00
|
|
|
print_footer($course);
|
2005-03-06 06:20:37 +00:00
|
|
|
exit;
|
2002-07-31 14:19:35 +00:00
|
|
|
}
|
|
|
|
|
2004-07-01 22:29:04 +00:00
|
|
|
require_login(0, false); // Script is useless unless they're logged in
|
2003-01-23 02:50:38 +00:00
|
|
|
|
2003-01-02 14:49:23 +00:00
|
|
|
if ($post = data_submitted()) {
|
2006-08-08 05:13:06 +00:00
|
|
|
if (empty($post->course)) {
|
|
|
|
error('No course was defined!');
|
2004-11-23 03:43:24 +00:00
|
|
|
}
|
|
|
|
|
2006-08-08 05:13:06 +00:00
|
|
|
if (!$course = get_record('course', 'id', $post->course)) {
|
2004-11-23 03:43:24 +00:00
|
|
|
error('Could not find specified course!');
|
|
|
|
}
|
2006-08-16 03:24:43 +00:00
|
|
|
|
2004-11-23 03:43:24 +00:00
|
|
|
if (!empty($course->lang)) { // Override current language
|
|
|
|
$CFG->courselang = $course->lang;
|
2004-07-13 14:11:17 +00:00
|
|
|
}
|
2002-07-31 14:19:35 +00:00
|
|
|
|
2003-04-24 14:05:47 +00:00
|
|
|
if (empty($SESSION->fromurl)) {
|
2006-08-08 05:13:06 +00:00
|
|
|
$errordestination = "$CFG->wwwroot/mod/forum/view.php?f=$post->forum";
|
2003-04-24 14:05:47 +00:00
|
|
|
} else {
|
|
|
|
$errordestination = $SESSION->fromurl;
|
|
|
|
}
|
|
|
|
|
2006-08-27 20:45:04 +00:00
|
|
|
$post->subject = clean_param(strip_tags($post->subject, '<lang><span>'), PARAM_CLEAN); // Strip all tags except multilang
|
2004-03-10 02:19:34 +00:00
|
|
|
|
2006-08-27 20:45:04 +00:00
|
|
|
//$post->message will be cleaned later before display
|
2002-07-31 14:19:35 +00:00
|
|
|
|
2004-04-25 02:15:48 +00:00
|
|
|
$post->attachment = isset($_FILES['attachment']) ? $_FILES['attachment'] : NULL;
|
2002-09-01 14:34:38 +00:00
|
|
|
|
2006-08-08 05:13:06 +00:00
|
|
|
if (!$cm = get_coursemodule_from_instance("forum", $post->forum, $course->id)) { // For the logs
|
2004-01-31 14:47:57 +00:00
|
|
|
$cm->id = 0;
|
|
|
|
}
|
2006-08-16 03:24:43 +00:00
|
|
|
$modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
|
2006-08-27 20:45:04 +00:00
|
|
|
trusttext_after_edit($post->message, $modcontext);
|
2004-01-31 14:47:57 +00:00
|
|
|
|
2006-08-08 05:13:06 +00:00
|
|
|
if (!$post->subject or !$post->message) {
|
2003-04-24 14:05:47 +00:00
|
|
|
$post->error = get_string("emptymessage", "forum");
|
2002-09-01 14:34:38 +00:00
|
|
|
|
2006-08-08 05:13:06 +00:00
|
|
|
} else if ($post->edit) { // Updating a post
|
|
|
|
$post->id = $post->edit;
|
2006-05-19 20:18:05 +00:00
|
|
|
$message = '';
|
2005-11-25 07:11:20 +00:00
|
|
|
|
2006-08-08 05:13:06 +00:00
|
|
|
//fix for bug #4314
|
2006-08-09 06:59:28 +00:00
|
|
|
if (!$realpost = get_record('forum_posts','id',$post->id)) {
|
2006-08-08 05:13:06 +00:00
|
|
|
$realpost = new object;
|
|
|
|
$realpost->userid = -1;
|
|
|
|
}
|
|
|
|
|
2006-08-14 05:55:40 +00:00
|
|
|
if ( !(($realpost->userid == $USER->id && has_capability('mod/forum:replypost', $modcontext)) ||
|
|
|
|
has_capability('mod/forum:editanypost', $modcontext)) ) {
|
2006-08-08 05:13:06 +00:00
|
|
|
error("You can not update this post");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (get_field('forum', 'type', 'id', $forum) == 'news' && !$post->parent) {
|
|
|
|
$updatediscussion->id = $post->discussion;
|
2005-11-10 22:50:03 +00:00
|
|
|
if (empty($post->timestartdisabled)) {
|
|
|
|
$updatediscussion->timestart = make_timestamp($post->timestartyear, $post->timestartmonth, $post->timestartday);
|
|
|
|
} else {
|
|
|
|
$updatediscussion->timestart = 0;
|
|
|
|
}
|
|
|
|
if (empty($post->timeenddisabled)) {
|
|
|
|
$updatediscussion->timeend = make_timestamp($post->timeendyear, $post->timeendmonth, $post->timeendday);
|
|
|
|
} else {
|
|
|
|
$updatediscussion->timeend = 0;
|
|
|
|
}
|
|
|
|
if (empty($post->timeenddisabled) && $updatediscussion->timeend <= $updatediscussion->timestart) {
|
|
|
|
$post->error = get_string('timestartenderror', 'forum');
|
|
|
|
} elseif (!update_record('forum_discussions', $updatediscussion)) {
|
|
|
|
error(get_string("couldnotupdate", "forum"), $errordestination);
|
|
|
|
}
|
|
|
|
}
|
2006-04-05 02:15:10 +00:00
|
|
|
|
2005-11-10 22:50:03 +00:00
|
|
|
if (!isset($post->error)) {
|
|
|
|
|
2006-08-08 05:13:06 +00:00
|
|
|
if (forum_update_post($post,$message)) {
|
2004-09-21 11:41:58 +00:00
|
|
|
|
2006-04-05 02:15:10 +00:00
|
|
|
add_to_log($course->id, "forum", "update post",
|
2006-08-08 05:13:06 +00:00
|
|
|
"discuss.php?d=$post->discussion&parent=$post->id", "$post->id", $cm->id);
|
2004-01-31 14:47:57 +00:00
|
|
|
|
2006-04-05 02:15:10 +00:00
|
|
|
$timemessage = 2;
|
|
|
|
if (!empty($message)) { // if we're printing stuff about the file upload
|
|
|
|
$timemessage = 4;
|
|
|
|
}
|
|
|
|
$message .= '<br />'.get_string("postupdated", "forum");
|
2004-09-21 11:41:58 +00:00
|
|
|
|
2006-08-08 05:13:06 +00:00
|
|
|
if ($subscribemessage = forum_post_subscription($post)) {
|
2006-04-05 02:15:10 +00:00
|
|
|
$timemessage = 4;
|
|
|
|
}
|
2006-08-08 05:13:06 +00:00
|
|
|
redirect(forum_go_back_to("discuss.php?d=$post->discussion#$post->id"), $message.$subscribemessage, $timemessage);
|
2003-05-13 13:53:36 +00:00
|
|
|
|
2006-04-05 02:15:10 +00:00
|
|
|
} else {
|
|
|
|
error(get_string("couldnotupdate", "forum"), $errordestination);
|
|
|
|
}
|
|
|
|
exit;
|
2005-11-10 22:50:03 +00:00
|
|
|
}
|
2006-08-09 06:59:28 +00:00
|
|
|
|
2006-08-08 05:13:06 +00:00
|
|
|
} else if ($post->discussion) { // Adding a new post to an existing discussion
|
2004-09-20 00:04:44 +00:00
|
|
|
$message = '';
|
2006-08-08 05:13:06 +00:00
|
|
|
if ($post->id = forum_add_new_post($post,$message)) {
|
2004-01-31 14:47:57 +00:00
|
|
|
|
2004-11-23 03:43:24 +00:00
|
|
|
add_to_log($course->id, "forum", "add post",
|
2006-08-08 05:13:06 +00:00
|
|
|
"discuss.php?d=$post->discussion&parent=$post->id", "$post->id", $cm->id);
|
2004-01-31 14:47:57 +00:00
|
|
|
|
2003-05-13 13:53:36 +00:00
|
|
|
$timemessage = 2;
|
2004-09-20 00:04:44 +00:00
|
|
|
if (!empty($message)) { // if we're printing stuff about the file upload
|
|
|
|
$timemessage = 4;
|
|
|
|
}
|
|
|
|
$message .= '<br />'.get_string("postadded", "forum", format_time($CFG->maxeditingtime));
|
2003-05-13 13:53:36 +00:00
|
|
|
|
2006-08-08 05:13:06 +00:00
|
|
|
if ($subscribemessage = forum_post_subscription($post)) {
|
2003-05-13 13:53:36 +00:00
|
|
|
$timemessage = 4;
|
2002-07-31 14:19:35 +00:00
|
|
|
}
|
|
|
|
|
2006-08-27 20:45:04 +00:00
|
|
|
if (!empty($post->mailnow)) {
|
2006-01-19 23:52:08 +00:00
|
|
|
$message .= get_string("postmailnow", "forum");
|
|
|
|
$timemessage = 4;
|
|
|
|
}
|
|
|
|
|
2006-08-08 05:13:06 +00:00
|
|
|
redirect(forum_go_back_to("discuss.php?d=$post->discussion#$post->id"), $message.$subscribemessage, $timemessage);
|
2003-05-13 13:53:36 +00:00
|
|
|
|
2002-07-31 14:19:35 +00:00
|
|
|
} else {
|
2004-09-21 11:41:58 +00:00
|
|
|
error(get_string("couldnotadd", "forum"), $errordestination);
|
2002-07-31 14:19:35 +00:00
|
|
|
}
|
2003-04-24 14:05:47 +00:00
|
|
|
exit;
|
|
|
|
|
2006-08-08 05:13:06 +00:00
|
|
|
} else { // Adding a new discussion
|
|
|
|
$post->mailnow = empty($post->mailnow) ? 0 : 1;
|
|
|
|
$discussion = $post;
|
|
|
|
$discussion->name = $post->subject;
|
2002-07-31 14:19:35 +00:00
|
|
|
$discussion->intro = $post->message;
|
2005-11-10 22:50:03 +00:00
|
|
|
$newstopic = false;
|
2006-08-08 05:13:06 +00:00
|
|
|
if (get_field('forum', 'type', 'id', $forum) == 'news' && !$post->parent) {
|
2005-11-10 22:50:03 +00:00
|
|
|
$newstopic = true;
|
|
|
|
}
|
|
|
|
if ($newstopic && empty($post->timestartdisabled)) {
|
|
|
|
$discussion->timestart = make_timestamp($post->timestartyear, $post->timestartmonth, $post->timestartday);
|
|
|
|
} else {
|
|
|
|
$discussion->timestart = 0;
|
|
|
|
}
|
|
|
|
if ($newstopic && empty($post->timeenddisabled)) {
|
|
|
|
$discussion->timeend = make_timestamp($post->timeendyear, $post->timeendmonth, $post->timeendday);
|
|
|
|
} else {
|
|
|
|
$discussion->timeend = 0;
|
|
|
|
}
|
|
|
|
if ($newstopic && empty($post->timeenddisabled) && $discussion->timeend <= $discussion->timestart) {
|
|
|
|
$post->error = get_string('timestartenderror', 'forum');
|
|
|
|
} else {
|
2006-04-05 02:15:10 +00:00
|
|
|
$message = '';
|
|
|
|
if ($discussion->id = forum_add_discussion($discussion,$message)) {
|
2005-11-10 22:50:03 +00:00
|
|
|
|
2006-04-05 02:15:10 +00:00
|
|
|
add_to_log($course->id, "forum", "add discussion",
|
|
|
|
"discuss.php?d=$discussion->id", "$discussion->id", $cm->id);
|
2004-01-31 14:47:57 +00:00
|
|
|
|
2006-04-05 02:15:10 +00:00
|
|
|
$timemessage = 2;
|
|
|
|
if (!empty($message)) { // if we're printing stuff about the file upload
|
|
|
|
$timemessage = 4;
|
|
|
|
}
|
|
|
|
$message .= '<br />'.get_string("postadded", "forum", format_time($CFG->maxeditingtime));
|
2004-09-21 11:41:58 +00:00
|
|
|
|
2006-08-08 05:13:06 +00:00
|
|
|
if ($post->mailnow) {
|
2006-04-05 02:15:10 +00:00
|
|
|
$message .= get_string("postmailnow", "forum");
|
|
|
|
$timemessage = 4;
|
|
|
|
}
|
2006-01-19 23:52:08 +00:00
|
|
|
|
2006-04-05 02:15:10 +00:00
|
|
|
if ($subscribemessage = forum_post_subscription($discussion)) {
|
|
|
|
$timemessage = 4;
|
|
|
|
}
|
2003-05-13 13:53:36 +00:00
|
|
|
|
2006-08-08 05:13:06 +00:00
|
|
|
redirect(forum_go_back_to("view.php?f=$post->forum"), $message.$subscribemessage, $timemessage);
|
2003-05-13 13:53:36 +00:00
|
|
|
|
2006-04-05 02:15:10 +00:00
|
|
|
} else {
|
|
|
|
error(get_string("couldnotadd", "forum"), $errordestination);
|
|
|
|
}
|
2005-11-10 22:50:03 +00:00
|
|
|
|
2006-04-05 02:15:10 +00:00
|
|
|
exit;
|
2005-11-10 22:50:03 +00:00
|
|
|
}
|
2002-07-31 14:19:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-03-21 09:08:57 +00:00
|
|
|
if ($usehtmleditor = can_use_html_editor()) {
|
2002-10-10 09:27:49 +00:00
|
|
|
$defaultformat = FORMAT_HTML;
|
|
|
|
} else {
|
|
|
|
$defaultformat = FORMAT_MOODLE;
|
|
|
|
}
|
2002-07-31 14:19:35 +00:00
|
|
|
|
2006-08-08 05:13:06 +00:00
|
|
|
if (isset($post->error)) { // User is re-editing a failed posting
|
2003-04-24 14:05:47 +00:00
|
|
|
|
|
|
|
// Set up all the required objects again, and reuse the same $post
|
|
|
|
|
|
|
|
if (! $forum = get_record("forum", "id", $post->forum)) {
|
|
|
|
error("The forum number was incorrect ($post->forum)");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! $course = get_record("course", "id", $forum->course)) {
|
|
|
|
error("The course number was incorrect ($forum->course)");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($post->parent)) {
|
|
|
|
if (! $parent = forum_get_post_full($post->parent)) {
|
|
|
|
error("Parent post ID was incorrect ($post->parent)");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($post->discussion)) {
|
|
|
|
if (! $discussion = get_record("forum_discussions", "id", $post->discussion)) {
|
|
|
|
error("This post is not part of a discussion! ($post->discussion)");
|
|
|
|
}
|
2006-01-18 04:14:50 +00:00
|
|
|
} else {
|
|
|
|
$discussion = new stdClass();
|
|
|
|
$newstopic = false;
|
|
|
|
if ($forum->type == 'news' && !$post->parent) {
|
|
|
|
$newstopic = true;
|
|
|
|
}
|
|
|
|
if ($newstopic && empty($post->timestartdisabled)) {
|
|
|
|
$discussion->timestart = make_timestamp($post->timestartyear, $post->timestartmonth, $post->timestartday);
|
|
|
|
} else {
|
|
|
|
$discussion->timestart = 0;
|
|
|
|
}
|
|
|
|
if ($newstopic && empty($post->timeenddisabled)) {
|
|
|
|
$discussion->timeend = make_timestamp($post->timeendyear, $post->timeendmonth, $post->timeendday);
|
|
|
|
} else {
|
|
|
|
$discussion->timeend = 0;
|
|
|
|
}
|
2003-04-24 14:05:47 +00:00
|
|
|
}
|
|
|
|
|
2006-08-08 05:13:06 +00:00
|
|
|
} else if (!empty($forum)) { // User is starting a new discussion in a forum
|
2002-07-31 14:19:35 +00:00
|
|
|
|
2006-08-08 05:13:06 +00:00
|
|
|
$SESSION->fromurl = $_SERVER["HTTP_REFERER"];
|
2002-07-31 14:19:35 +00:00
|
|
|
|
|
|
|
if (! $forum = get_record("forum", "id", $forum)) {
|
|
|
|
error("The forum number was incorrect ($forum)");
|
|
|
|
}
|
|
|
|
if (! $course = get_record("course", "id", $forum->course)) {
|
2003-04-24 14:05:47 +00:00
|
|
|
error("The course number was incorrect ($forum->course)");
|
2002-07-31 14:19:35 +00:00
|
|
|
}
|
2006-08-16 03:24:43 +00:00
|
|
|
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
|
|
|
|
|
2002-08-01 03:50:27 +00:00
|
|
|
if (! forum_user_can_post_discussion($forum)) {
|
2002-07-31 14:19:35 +00:00
|
|
|
error("Sorry, but you can not post a new discussion in this forum.");
|
|
|
|
}
|
2006-08-16 03:24:43 +00:00
|
|
|
|
2004-04-30 01:54:56 +00:00
|
|
|
if ($cm = get_coursemodule_from_instance("forum", $forum->id, $course->id)) {
|
2006-08-14 05:55:40 +00:00
|
|
|
if (!$cm->visible and !has_capability('moodle/course:manageactivities', $coursecontext)) {
|
2004-04-30 01:54:56 +00:00
|
|
|
error(get_string("activityiscurrentlyhidden"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-31 14:19:35 +00:00
|
|
|
// Load up the $post variable.
|
|
|
|
|
|
|
|
$post->course = $course->id;
|
|
|
|
$post->forum = $forum->id;
|
|
|
|
$post->discussion = 0; // ie discussion # not defined yet
|
|
|
|
$post->parent = 0;
|
|
|
|
$post->subject = "";
|
2002-12-23 09:39:26 +00:00
|
|
|
$post->userid = $USER->id;
|
2002-07-31 14:19:35 +00:00
|
|
|
$post->message = "";
|
2002-10-10 09:27:49 +00:00
|
|
|
$post->format = $defaultformat;
|
2002-07-31 14:19:35 +00:00
|
|
|
|
2006-08-08 05:13:06 +00:00
|
|
|
$post->groupid = get_current_group($course->id);
|
|
|
|
if ($post->groupid == 0) {
|
|
|
|
$post->groupid = -1;
|
|
|
|
}
|
|
|
|
|
2002-08-01 03:50:27 +00:00
|
|
|
forum_set_return();
|
|
|
|
|
2006-08-08 05:13:06 +00:00
|
|
|
} else if (!empty($reply)) { // User is writing a new reply
|
2002-07-31 14:19:35 +00:00
|
|
|
|
2002-08-01 03:50:27 +00:00
|
|
|
if (! $parent = forum_get_post_full($reply)) {
|
2004-08-07 02:44:38 +00:00
|
|
|
error("Parent post ID was incorrect");
|
2002-07-31 14:19:35 +00:00
|
|
|
}
|
|
|
|
if (! $discussion = get_record("forum_discussions", "id", $parent->discussion)) {
|
2004-08-07 02:44:38 +00:00
|
|
|
error("This post is not part of a discussion!");
|
2002-07-31 14:19:35 +00:00
|
|
|
}
|
|
|
|
if (! $forum = get_record("forum", "id", $discussion->forum)) {
|
|
|
|
error("The forum number was incorrect ($discussion->forum)");
|
|
|
|
}
|
|
|
|
if (! $course = get_record("course", "id", $discussion->course)) {
|
|
|
|
error("The course number was incorrect ($discussion->course)");
|
|
|
|
}
|
2006-08-16 03:24:43 +00:00
|
|
|
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
|
|
|
|
|
2002-10-25 07:22:59 +00:00
|
|
|
if (! forum_user_can_post($forum)) {
|
|
|
|
error("Sorry, but you can not post in this forum.");
|
|
|
|
}
|
2006-08-16 03:24:43 +00:00
|
|
|
|
2004-01-23 12:09:25 +00:00
|
|
|
if ($cm = get_coursemodule_from_instance("forum", $forum->id, $course->id)) {
|
2006-08-08 05:13:06 +00:00
|
|
|
if (groupmode($course, $cm)) { // Make sure user can post here
|
2005-04-13 09:19:48 +00:00
|
|
|
$mygroupid = mygroupid($course->id);
|
2005-11-08 07:19:27 +00:00
|
|
|
if (!((empty($mygroupid) and $discussion->groupid == -1) || (ismember($discussion->groupid)/*$mygroupid == $discussion->groupid*/))) {
|
2004-01-23 12:09:25 +00:00
|
|
|
error("Sorry, but you can not post in this discussion.");
|
|
|
|
}
|
|
|
|
}
|
2006-08-14 05:55:40 +00:00
|
|
|
if (!$cm->visible and !has_capability('moodle/course:manageactivities', $coursecontext)) {
|
2004-04-30 01:54:56 +00:00
|
|
|
error(get_string("activityiscurrentlyhidden"));
|
|
|
|
}
|
2004-01-23 12:09:25 +00:00
|
|
|
}
|
|
|
|
|
2002-07-31 14:19:35 +00:00
|
|
|
// Load up the $post variable.
|
|
|
|
|
|
|
|
$post->course = $course->id;
|
|
|
|
$post->forum = $forum->id;
|
|
|
|
$post->discussion = $parent->discussion;
|
|
|
|
$post->parent = $parent->id;
|
|
|
|
$post->subject = $parent->subject;
|
2002-12-23 09:39:26 +00:00
|
|
|
$post->userid = $USER->id;
|
2002-07-31 14:19:35 +00:00
|
|
|
$post->message = "";
|
2002-10-10 09:27:49 +00:00
|
|
|
$post->format = $defaultformat;
|
2002-07-31 14:19:35 +00:00
|
|
|
|
2004-05-24 10:04:59 +00:00
|
|
|
$strre = get_string('re', 'forum');
|
|
|
|
if (!(substr($post->subject, 0, strlen($strre)) == $strre)) {
|
|
|
|
$post->subject = $strre.' '.$post->subject;
|
2002-07-31 14:19:35 +00:00
|
|
|
}
|
|
|
|
|
2003-06-20 06:35:09 +00:00
|
|
|
unset($SESSION->fromdiscussion);
|
2002-07-31 14:19:35 +00:00
|
|
|
|
2006-08-08 05:13:06 +00:00
|
|
|
} else if (!empty($edit)) { // User is editing their own post
|
2004-02-18 03:30:05 +00:00
|
|
|
|
2002-08-01 03:50:27 +00:00
|
|
|
if (! $post = forum_get_post_full($edit)) {
|
2002-07-31 14:19:35 +00:00
|
|
|
error("Post ID was incorrect");
|
|
|
|
}
|
2006-08-08 05:13:06 +00:00
|
|
|
if (($post->userid <> $USER->id) and
|
2006-08-14 05:55:40 +00:00
|
|
|
!has_capability('mod/forum:editanypost', $modcontext)) {
|
2002-07-31 14:19:35 +00:00
|
|
|
error("You can't edit other people's posts!");
|
|
|
|
}
|
|
|
|
if ($post->parent) {
|
2002-08-01 03:50:27 +00:00
|
|
|
if (! $parent = forum_get_post_full($post->parent)) {
|
2002-07-31 14:19:35 +00:00
|
|
|
error("Parent post ID was incorrect ($post->parent)");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (! $discussion = get_record("forum_discussions", "id", $post->discussion)) {
|
|
|
|
error("This post is not part of a discussion! ($reply)");
|
|
|
|
}
|
|
|
|
if (! $forum = get_record("forum", "id", $discussion->forum)) {
|
|
|
|
error("The forum number was incorrect ($discussion->forum)");
|
|
|
|
}
|
2005-11-10 22:50:03 +00:00
|
|
|
if (!($forum->type == 'news' && !$post->parent && $discussion->timestart > time())) {
|
2006-08-08 05:13:06 +00:00
|
|
|
if (((time() - $post->created) > $CFG->maxeditingtime) and
|
2006-08-14 05:55:40 +00:00
|
|
|
!has_capability('mod/forum:editanypost', $modcontext)) {
|
2006-08-08 05:13:06 +00:00
|
|
|
error( get_string("maxtimehaspassed", "forum", format_time($CFG->maxeditingtime)) );
|
2005-11-10 22:50:03 +00:00
|
|
|
}
|
|
|
|
}
|
2002-07-31 14:19:35 +00:00
|
|
|
if (! $course = get_record("course", "id", $discussion->course)) {
|
|
|
|
error("The course number was incorrect ($discussion->course)");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load up the $post variable.
|
|
|
|
|
|
|
|
$post->edit = $edit;
|
|
|
|
|
|
|
|
$post->course = $course->id;
|
|
|
|
$post->forum = $forum->id;
|
|
|
|
|
2003-06-20 06:35:09 +00:00
|
|
|
unset($SESSION->fromdiscussion);
|
2002-07-31 14:19:35 +00:00
|
|
|
|
|
|
|
|
2006-08-08 05:13:06 +00:00
|
|
|
} else if (!empty($delete)) { // User is deleting a post
|
2002-07-31 14:19:35 +00:00
|
|
|
|
2002-08-01 03:50:27 +00:00
|
|
|
if (! $post = forum_get_post_full($delete)) {
|
2002-07-31 14:19:35 +00:00
|
|
|
error("Post ID was incorrect");
|
|
|
|
}
|
|
|
|
if (! $discussion = get_record("forum_discussions", "id", $post->discussion)) {
|
|
|
|
error("This post is not part of a discussion!");
|
|
|
|
}
|
2002-08-05 09:48:17 +00:00
|
|
|
if (! $forum = get_record("forum", "id", $discussion->forum)) {
|
|
|
|
error("The forum number was incorrect ($discussion->forum)");
|
|
|
|
}
|
2006-08-16 03:24:43 +00:00
|
|
|
if (!$cm = get_coursemodule_from_instance("forum", $forum->id, $forum->course)) {
|
|
|
|
$cm->id = 0;
|
|
|
|
} else {
|
|
|
|
$modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
|
|
|
|
}
|
2006-08-14 05:55:40 +00:00
|
|
|
if ( !(($post->userid == $USER->id && has_capability('mod/forum:deleteownpost', $modcontext))
|
|
|
|
|| has_capability('mod/forum:deleteanypost', $modcontext)) ) {
|
2006-08-08 05:13:06 +00:00
|
|
|
error("You can't delete this post!");
|
2002-08-05 09:48:17 +00:00
|
|
|
}
|
2004-07-13 14:11:17 +00:00
|
|
|
if (!empty($forum->course)) {
|
|
|
|
if ($course = get_record('course', 'id', $forum->course)) {
|
|
|
|
if (!empty($course->lang)) {
|
|
|
|
$CFG->courselang = $course->lang;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-07-31 14:19:35 +00:00
|
|
|
|
2005-04-19 11:25:59 +00:00
|
|
|
$replycount = forum_count_replies($post);
|
|
|
|
|
2006-08-08 05:13:06 +00:00
|
|
|
if (!empty($confirm)) { // User has confirmed the delete
|
2002-07-31 14:19:35 +00:00
|
|
|
|
|
|
|
if ($post->totalscore) {
|
2004-09-21 11:41:58 +00:00
|
|
|
notice(get_string("couldnotdeleteratings", "forum"),
|
2002-08-01 03:50:27 +00:00
|
|
|
forum_go_back_to("discuss.php?d=$post->discussion"));
|
2002-07-31 14:19:35 +00:00
|
|
|
|
2006-08-14 05:55:40 +00:00
|
|
|
} else if ($replycount && !has_capability('mod/forum:deleteanypost', $modcontext)) {
|
2002-09-03 13:11:40 +00:00
|
|
|
error(get_string("couldnotdeletereplies", "forum"),
|
2005-02-14 00:04:09 +00:00
|
|
|
forum_go_back_to("discuss.php?d=$post->discussion"));
|
2002-07-31 14:19:35 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
if (! $post->parent) { // post is a discussion topic as well, so delete discussion
|
2002-08-05 09:48:17 +00:00
|
|
|
if ($forum->type == "single") {
|
2004-09-21 11:41:58 +00:00
|
|
|
notice("Sorry, but you are not allowed to delete that discussion!",
|
2002-08-05 09:48:17 +00:00
|
|
|
forum_go_back_to("discuss.php?d=$post->discussion"));
|
|
|
|
}
|
2002-07-31 14:19:35 +00:00
|
|
|
forum_delete_discussion($discussion);
|
|
|
|
|
2004-09-21 11:41:58 +00:00
|
|
|
add_to_log($discussion->course, "forum", "delete discussion",
|
2004-02-22 11:50:09 +00:00
|
|
|
"view.php?id=$cm->id", "$forum->id", $cm->id);
|
2004-01-31 14:47:57 +00:00
|
|
|
|
2004-09-21 11:41:58 +00:00
|
|
|
redirect("view.php?f=$discussion->forum",
|
2002-09-03 13:11:40 +00:00
|
|
|
get_string("deleteddiscussion", "forum"), 1);
|
2002-07-31 14:19:35 +00:00
|
|
|
|
2006-08-14 05:55:40 +00:00
|
|
|
} else if (forum_delete_post($post, has_capability('mod/forum:deleteanypost', $modcontext))) {
|
2002-07-31 14:19:35 +00:00
|
|
|
|
2004-09-21 11:41:58 +00:00
|
|
|
add_to_log($discussion->course, "forum", "delete post",
|
2004-01-31 14:47:57 +00:00
|
|
|
"discuss.php?d=$post->discussion", "$post->id", $cm->id);
|
|
|
|
|
2005-04-19 11:25:59 +00:00
|
|
|
$feedback = $replycount ? get_string('deletedposts', 'forum') : get_string('deletedpost', 'forum');
|
|
|
|
redirect(forum_go_back_to("discuss.php?d=$post->discussion"), $feedback, 1);
|
2002-07-31 14:19:35 +00:00
|
|
|
} else {
|
|
|
|
error("An error occurred while deleting record $post->id");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-08-08 05:13:06 +00:00
|
|
|
} else { // User just asked to delete something
|
2002-07-31 14:19:35 +00:00
|
|
|
|
2002-08-01 03:50:27 +00:00
|
|
|
forum_set_return();
|
2002-07-31 14:19:35 +00:00
|
|
|
|
2005-04-19 11:25:59 +00:00
|
|
|
if ($replycount) {
|
2006-08-14 05:55:40 +00:00
|
|
|
if (!has_capability('mof/forum:deleteanypost', $modcontext)) {
|
2005-04-19 11:25:59 +00:00
|
|
|
error(get_string("couldnotdeletereplies", "forum"),
|
|
|
|
forum_go_back_to("discuss.php?d=$post->discussion"));
|
|
|
|
}
|
|
|
|
print_header();
|
|
|
|
notice_yesno(get_string("deletesureplural", "forum", $replycount+1),
|
2006-08-08 05:13:06 +00:00
|
|
|
"post.php?delete=$delete&confirm=$delete",
|
2005-04-19 11:25:59 +00:00
|
|
|
$_SERVER["HTTP_REFERER"]);
|
|
|
|
|
|
|
|
forum_print_post($post, $course->id, $ownpost=false, $reply=false, $link=false);
|
|
|
|
if (empty($post->edit)) {
|
2005-04-26 16:27:51 +00:00
|
|
|
if (forum_tp_can_track_forums($forum) && forum_tp_is_tracked($forum)) {
|
2005-04-19 11:25:59 +00:00
|
|
|
$user_read_array = forum_tp_get_discussion_read_records($USER->id, $discussion->id);
|
|
|
|
} else {
|
|
|
|
$user_read_array = array();
|
|
|
|
}
|
|
|
|
forum_print_posts_nested($post->id, $course->id, false, false, $user_read_array, $forum->id);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
print_header();
|
|
|
|
notice_yesno(get_string("deletesure", "forum", $replycount),
|
2006-08-08 05:13:06 +00:00
|
|
|
"post.php?delete=$delete&confirm=$delete",
|
2005-04-19 11:25:59 +00:00
|
|
|
$_SERVER["HTTP_REFERER"]);
|
|
|
|
forum_print_post($post, $forum->course, $ownpost=false, $reply=false, $link=false);
|
|
|
|
}
|
2004-09-21 11:41:58 +00:00
|
|
|
|
2002-07-31 14:19:35 +00:00
|
|
|
}
|
2004-09-16 17:13:57 +00:00
|
|
|
print_footer($course);
|
2002-07-31 14:19:35 +00:00
|
|
|
die;
|
|
|
|
|
|
|
|
|
2006-08-08 05:13:06 +00:00
|
|
|
} else if (!empty($prune)) { // Teacher is pruning
|
2004-09-21 11:41:58 +00:00
|
|
|
|
2005-04-19 16:05:50 +00:00
|
|
|
if (!$post = forum_get_post_full($prune)) {
|
2004-05-30 17:25:26 +00:00
|
|
|
error("Post ID was incorrect");
|
|
|
|
}
|
2005-04-19 16:05:50 +00:00
|
|
|
if (!$discussion = get_record("forum_discussions", "id", $post->discussion)) {
|
2004-05-30 17:25:26 +00:00
|
|
|
error("This post is not part of a discussion!");
|
|
|
|
}
|
2005-04-19 16:05:50 +00:00
|
|
|
if (!$forum = get_record("forum", "id", $discussion->forum)) {
|
2004-05-30 17:25:26 +00:00
|
|
|
error("The forum number was incorrect ($discussion->forum)");
|
|
|
|
}
|
2006-08-14 05:55:40 +00:00
|
|
|
if (!has_capability('mod/forum:splitdiscussions', $modcontext)) {
|
2004-06-29 03:49:51 +00:00
|
|
|
error("You can't split discussions!");
|
2004-05-30 17:25:26 +00:00
|
|
|
}
|
|
|
|
if (!$post->parent) {
|
|
|
|
error('This is already the first post in the discussion');
|
|
|
|
}
|
2005-04-19 16:05:50 +00:00
|
|
|
if (!$cm = get_coursemodule_from_instance("forum", $forum->id, $forum->course)) { // For the logs
|
|
|
|
$cm->id = 0;
|
|
|
|
}
|
2004-05-30 17:25:26 +00:00
|
|
|
|
2006-08-08 05:13:06 +00:00
|
|
|
if (!empty($name)) { // User has confirmed the prune
|
2004-09-21 11:41:58 +00:00
|
|
|
|
2004-05-30 17:25:26 +00:00
|
|
|
$newdiscussion->course = $discussion->course;
|
|
|
|
$newdiscussion->forum = $discussion->forum;
|
2006-08-08 05:13:06 +00:00
|
|
|
$newdiscussion->name = $name;
|
2004-05-30 17:25:26 +00:00
|
|
|
$newdiscussion->firstpost = $post->id;
|
|
|
|
$newdiscussion->userid = $discussion->userid;
|
|
|
|
$newdiscussion->groupid = $discussion->groupid;
|
|
|
|
$newdiscussion->assessed = $discussion->assessed;
|
|
|
|
$newdiscussion->usermodified = $post->userid;
|
2005-11-10 22:50:03 +00:00
|
|
|
$newdiscussion->timestart = $discussion->timestart;
|
|
|
|
$newdiscussion->timeend = $discussion->timeend;
|
2004-09-21 11:41:58 +00:00
|
|
|
|
2004-05-30 17:25:26 +00:00
|
|
|
if (!$newid = insert_record('forum_discussions', $newdiscussion)) {
|
|
|
|
error('Could not create new discussion');
|
|
|
|
}
|
2004-09-21 11:41:58 +00:00
|
|
|
|
2004-07-08 14:39:15 +00:00
|
|
|
$newpost->id = $post->id;
|
|
|
|
$newpost->parent = 0;
|
2006-08-08 05:13:06 +00:00
|
|
|
$newpost->subject = $name;
|
2004-06-29 03:46:17 +00:00
|
|
|
|
2004-07-08 14:39:15 +00:00
|
|
|
if (!update_record("forum_posts", $newpost)) {
|
2004-06-29 03:46:17 +00:00
|
|
|
error('Could not update the original post');
|
|
|
|
}
|
|
|
|
|
2004-05-30 17:25:26 +00:00
|
|
|
forum_change_discussionid($post->id, $newid);
|
2004-09-21 11:41:58 +00:00
|
|
|
|
2005-04-28 07:42:14 +00:00
|
|
|
// update last post in each discussion
|
|
|
|
forum_discussion_update_last_post($discussion->id);
|
|
|
|
forum_discussion_update_last_post($newid);
|
2004-05-30 17:25:26 +00:00
|
|
|
|
2004-09-21 11:41:58 +00:00
|
|
|
add_to_log($discussion->course, "forum", "prune post",
|
2004-05-30 17:25:26 +00:00
|
|
|
"discuss.php?d=$newid", "$post->id", $cm->id);
|
|
|
|
|
2004-06-29 03:46:17 +00:00
|
|
|
redirect(forum_go_back_to("discuss.php?d=$newid"), get_string("prunedpost", "forum"), 1);
|
2004-05-30 17:25:26 +00:00
|
|
|
|
|
|
|
} else { // User just asked to prune something
|
|
|
|
|
|
|
|
$course = get_record('course', 'id', $forum->course);
|
|
|
|
$strforums = get_string("modulenameplural", "forum");
|
2005-03-26 17:11:30 +00:00
|
|
|
print_header_simple(format_string($discussion->name).": ".format_string($post->subject), "",
|
2004-09-21 11:41:58 +00:00
|
|
|
"<a href=\"../forum/index.php?id=$course->id\">$strforums</a> ->
|
2005-03-26 01:57:40 +00:00
|
|
|
<a href=\"view.php?f=$forum->id\">".format_string($forum->name,true)."</a> ->
|
2005-03-26 11:43:16 +00:00
|
|
|
<a href=\"discuss.php?d=$discussion->id\">".format_string($post->subject,true)."</a> -> ".
|
2004-05-30 17:25:26 +00:00
|
|
|
get_string("prune", "forum"), '', "", true, "", navmenu($course, $cm));
|
2004-09-21 11:41:58 +00:00
|
|
|
|
2004-05-30 17:25:26 +00:00
|
|
|
print_heading(get_string('pruneheading', 'forum'));
|
2004-06-29 03:46:17 +00:00
|
|
|
echo '<center>';
|
2004-09-21 11:41:58 +00:00
|
|
|
|
2004-05-30 17:25:26 +00:00
|
|
|
include('prune.html');
|
2004-09-21 11:41:58 +00:00
|
|
|
|
2004-05-30 17:25:26 +00:00
|
|
|
forum_print_post($post, $forum->course, $ownpost=false, $reply=false, $link=false);
|
2004-09-16 17:13:57 +00:00
|
|
|
echo '</center>';
|
2004-05-30 17:25:26 +00:00
|
|
|
}
|
2004-09-16 17:13:57 +00:00
|
|
|
print_footer($course);
|
2004-05-30 17:25:26 +00:00
|
|
|
die;
|
|
|
|
|
|
|
|
|
2002-07-31 14:19:35 +00:00
|
|
|
} else {
|
|
|
|
error("No operation specified");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-09-21 11:41:58 +00:00
|
|
|
// To get here they need to edit a post, and the $post
|
2002-07-31 14:19:35 +00:00
|
|
|
// variable will be loaded with all the particulars,
|
|
|
|
// so bring up the form.
|
|
|
|
|
|
|
|
// $course, $forum are defined. $discussion is for edit and reply only.
|
|
|
|
|
2005-02-16 10:40:48 +00:00
|
|
|
$cm = get_coursemodule_from_instance("forum", $forum->id, $course->id);
|
|
|
|
|
|
|
|
require_login($course->id, false, $cm);
|
2002-07-31 14:19:35 +00:00
|
|
|
|
2006-08-27 20:45:04 +00:00
|
|
|
$modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
|
2002-11-10 08:43:44 +00:00
|
|
|
|
2002-07-31 14:19:35 +00:00
|
|
|
if ($post->discussion) {
|
2002-12-20 14:44:14 +00:00
|
|
|
if (! $toppost = get_record("forum_posts", "discussion", $post->discussion, "parent", 0)) {
|
2002-07-31 14:19:35 +00:00
|
|
|
error("Could not find top parent of post $post->id");
|
|
|
|
}
|
|
|
|
} else {
|
2005-01-19 13:16:29 +00:00
|
|
|
$toppost->subject = ($forum->type == "news") ? get_string("addanewtopic", "forum") :
|
2004-12-14 06:26:43 +00:00
|
|
|
get_string("addanewdiscussion", "forum");
|
2002-07-31 14:19:35 +00:00
|
|
|
}
|
|
|
|
|
2003-11-04 12:42:42 +00:00
|
|
|
if (empty($post->subject)) {
|
2002-12-30 03:38:59 +00:00
|
|
|
$formstart = "theform.subject";
|
2003-11-04 12:42:42 +00:00
|
|
|
} else {
|
|
|
|
$formstart = "";
|
2002-07-31 14:19:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($post->parent) {
|
2005-03-26 11:43:16 +00:00
|
|
|
$navtail = "<a href=\"discuss.php?d=$discussion->id\">".format_string($toppost->subject,true)."</a> -> ".get_string("editing", "forum");
|
2002-07-31 14:19:35 +00:00
|
|
|
} else {
|
2005-03-26 11:43:16 +00:00
|
|
|
$navtail = format_string($toppost->subject);
|
2002-07-31 14:19:35 +00:00
|
|
|
}
|
|
|
|
|
2002-12-29 17:32:32 +00:00
|
|
|
if (empty($post->edit)) {
|
|
|
|
$post->edit = "";
|
|
|
|
}
|
|
|
|
|
2002-09-03 13:11:40 +00:00
|
|
|
$strforums = get_string("modulenameplural", "forum");
|
|
|
|
|
2002-10-10 07:27:57 +00:00
|
|
|
|
2005-03-26 01:57:40 +00:00
|
|
|
$navmiddle = "<a href=\"../forum/index.php?id=$course->id\">$strforums</a> -> <a href=\"view.php?f=$forum->id\">".format_string($forum->name,true)."</a>";
|
2002-07-31 14:19:35 +00:00
|
|
|
|
2005-01-29 09:49:42 +00:00
|
|
|
if (empty($discussion->name)) {
|
2005-04-21 08:11:07 +00:00
|
|
|
if (empty($discussion)) {
|
|
|
|
$discussion = new object;
|
|
|
|
}
|
2002-12-29 17:32:32 +00:00
|
|
|
$discussion->name = $forum->name;
|
|
|
|
}
|
|
|
|
|
2002-07-31 14:19:35 +00:00
|
|
|
if ($course->category) {
|
2005-03-26 17:11:30 +00:00
|
|
|
print_header("$course->shortname: ".format_string($discussion->name).": ".format_string($toppost->subject), "$course->fullname",
|
2004-10-29 06:50:52 +00:00
|
|
|
"<a href=\"../../course/view.php?id=$course->id\">$course->shortname</a> ->
|
2003-11-04 12:42:42 +00:00
|
|
|
$navmiddle -> $navtail", $formstart, "", true, "", navmenu($course, $cm));
|
2005-01-19 13:16:29 +00:00
|
|
|
|
2002-07-31 14:19:35 +00:00
|
|
|
} else {
|
2005-03-26 17:11:30 +00:00
|
|
|
print_header("$course->shortname: ".format_string($discussion->name).": ".format_string($toppost->subject), "$course->fullname",
|
2002-12-29 17:32:32 +00:00
|
|
|
"$navmiddle -> $navtail", "$formstart", "", true, "", navmenu($course, $cm));
|
2002-07-31 14:19:35 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2006-01-16 04:57:48 +00:00
|
|
|
// checkup
|
2006-08-14 07:37:53 +00:00
|
|
|
if (!empty($parent) && !forum_user_can_see_post($forum, $discussion, $post)) {
|
2006-01-16 04:57:48 +00:00
|
|
|
error("You cannot reply to this post");
|
|
|
|
}
|
2006-08-08 05:13:06 +00:00
|
|
|
if (empty($parent) && !forum_user_can_post_discussion($forum)) {
|
2006-01-16 04:57:48 +00:00
|
|
|
error("You cannot start a new discussion in this forum");
|
|
|
|
}
|
|
|
|
|
2006-08-14 05:55:40 +00:00
|
|
|
if ($forum->type == 'qanda' && !has_capability('mod/forum:viewqandawithoutposting', $modcontext) &&
|
2006-08-08 05:13:06 +00:00
|
|
|
!forum_user_has_posted($forum->id,$discussion->id,$USER->id)) {
|
2006-01-16 04:57:48 +00:00
|
|
|
notify(get_string('qandanotify','forum'));
|
|
|
|
}
|
|
|
|
|
2006-01-16 08:42:09 +00:00
|
|
|
forum_check_throttling($forum);
|
|
|
|
|
2003-04-24 14:05:47 +00:00
|
|
|
if (!empty($parent)) {
|
2002-08-01 03:50:27 +00:00
|
|
|
forum_print_post($parent, $course->id, $ownpost=false, $reply=false, $link=false);
|
2003-12-12 08:46:24 +00:00
|
|
|
if (empty($post->edit)) {
|
2005-04-26 16:27:51 +00:00
|
|
|
if (forum_tp_can_track_forums($forum) && forum_tp_is_tracked($forum)) {
|
2005-01-29 09:49:42 +00:00
|
|
|
$user_read_array = forum_tp_get_discussion_read_records($USER->id, $discussion->id);
|
|
|
|
} else {
|
|
|
|
$user_read_array = array();
|
|
|
|
}
|
2006-08-14 05:55:40 +00:00
|
|
|
if ($forum->type != 'qanda' || forum_user_can_see_discussion($forum, $discussion, $modcontext)) {
|
2006-01-16 04:57:48 +00:00
|
|
|
forum_print_posts_threaded($parent->id, $course->id, 0, false, false, $user_read_array, $discussion->forum);
|
|
|
|
}
|
2003-12-12 08:46:24 +00:00
|
|
|
}
|
2005-03-06 06:48:48 +00:00
|
|
|
print_heading(get_string("yourreply", "forum").':');
|
2002-07-31 14:19:35 +00:00
|
|
|
} else {
|
2004-12-14 06:26:43 +00:00
|
|
|
$forum->intro = trim($forum->intro);
|
|
|
|
if (!empty($forum->intro)) {
|
|
|
|
print_simple_box(format_text($forum->intro), 'center');
|
|
|
|
}
|
2006-01-16 04:57:48 +00:00
|
|
|
if ($forum->type == 'qanda') {
|
|
|
|
print_heading(get_string('yournewquestion','forum'));
|
|
|
|
} else {
|
|
|
|
print_heading(get_string('yournewtopic', 'forum'));
|
|
|
|
}
|
2002-07-31 14:19:35 +00:00
|
|
|
}
|
2005-03-06 06:48:48 +00:00
|
|
|
echo '<center>';
|
2003-04-24 14:05:47 +00:00
|
|
|
if (!empty($post->error)) {
|
|
|
|
notify($post->error);
|
|
|
|
}
|
2005-03-06 06:48:48 +00:00
|
|
|
echo '</center>';
|
2002-07-31 14:19:35 +00:00
|
|
|
|
2006-04-05 02:15:10 +00:00
|
|
|
if ($USER->id != $post->userid) { // Not the original author, so add a message to the end
|
|
|
|
$data->date = userdate($post->modified);
|
|
|
|
if ($post->format == FORMAT_HTML) {
|
|
|
|
$data->name = '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$USER->id.'&course='.$post->course.'">'.
|
|
|
|
fullname($USER).'</a>';
|
|
|
|
$post->message .= '<p>(<span class="edited">'.get_string('editedby', 'forum', $data).'</span>)</p>';
|
|
|
|
} else {
|
|
|
|
$data->name = fullname($USER);
|
|
|
|
$post->message .= "\n\n(".get_string('editedby', 'forum', $data).')';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-25 14:28:47 +00:00
|
|
|
print_simple_box_start("center");
|
2002-07-31 14:19:35 +00:00
|
|
|
require("post.html");
|
|
|
|
print_simple_box_end();
|
|
|
|
|
2003-11-03 16:49:37 +00:00
|
|
|
if ($usehtmleditor) {
|
2004-06-04 06:17:30 +00:00
|
|
|
use_html_editor("message");
|
2003-11-03 16:49:37 +00:00
|
|
|
}
|
|
|
|
|
2002-07-31 14:19:35 +00:00
|
|
|
print_footer($course);
|
|
|
|
|
|
|
|
|
2006-08-16 03:24:43 +00:00
|
|
|
?>
|