diff --git a/mod/forum/lib.php b/mod/forum/lib.php
index 573a63db72d..0cffcc65a41 100644
--- a/mod/forum/lib.php
+++ b/mod/forum/lib.php
@@ -1984,11 +1984,14 @@ function forum_print_attachments($post, $return=NULL) {
return $imagereturn;
}
+/**
+ * If successful, this function returns the name of the file
+ * @param $post is a full post record, including course and forum
+ * @param $newfile is a full upload array from $_FILES
+ * @param $message is a string to hold the messages.
+ */
-function forum_add_attachment($post, $inputname) {
-// $post is a full post record, including course and forum
-// $newfile is a full upload array from $_FILES
-// If successful, this function returns the name of the file
+function forum_add_attachment($post, $inputname,&$message) {
global $CFG;
@@ -2001,15 +2004,16 @@ function forum_add_attachment($post, $inputname) {
}
require_once($CFG->dirroot.'/lib/uploadlib.php');
- $um = new upload_manager($inputname,true,false,$course,false,$forum->maxbytes);
+ $um = new upload_manager($inputname,true,false,$course,false,$forum->maxbytes,true,true);
$dir = forum_file_area_name($post);
if ($um->process_file_uploads($dir)) {
+ $message .= $um->get_errors();
return $um->get_new_filename();
}
- // upload manager will print any errors.
+ $message .= $um->get_errors();
}
-function forum_add_new_post($post) {
+function forum_add_new_post($post,&$message) {
$post->created = $post->modified = time();
$post->mailed = "0";
@@ -2020,7 +2024,7 @@ function forum_add_new_post($post) {
return false;
}
- if ($post->attachment = forum_add_attachment($post, 'attachment')) {
+ if ($post->attachment = forum_add_attachment($post, 'attachment',$message)) {
set_field("forum_posts", "attachment", $post->attachment, "id", $post->id);
}
@@ -2031,7 +2035,7 @@ function forum_add_new_post($post) {
return $post->id;
}
-function forum_update_post($post) {
+function forum_update_post($post,&$message) {
$post->modified = time();
@@ -2039,7 +2043,7 @@ function forum_update_post($post) {
set_field("forum_discussions", "name", $post->subject, "id", $post->discussion);
}
- if ($newfilename = forum_add_attachment($post, 'attachment')) {
+ if ($newfilename = forum_add_attachment($post, 'attachment',$message)) {
$post->attachment = $newfilename;
} else {
unset($post->attachment);
@@ -2052,7 +2056,7 @@ function forum_update_post($post) {
return update_record("forum_posts", $post);
}
-function forum_add_discussion($discussion) {
+function forum_add_discussion($discussion,&$message) {
// Given an object containing all the necessary data,
// create a new discussion and return the id
@@ -2080,7 +2084,7 @@ function forum_add_discussion($discussion) {
return 0;
}
- if ($post->attachment = forum_add_attachment($post, 'attachment')) {
+ if ($post->attachment = forum_add_attachment($post, 'attachment',$message)) {
set_field("forum_posts", "attachment", $post->attachment, "id", $post->id); //ignore errors
}
diff --git a/mod/forum/post.php b/mod/forum/post.php
index d2de7a1a96c..a6b6507e781 100644
--- a/mod/forum/post.php
+++ b/mod/forum/post.php
@@ -43,16 +43,20 @@
} else if ($post->edit) { // Updating a post
$post->id = $post->edit;
- if (forum_update_post($post)) {
-
+ $message = '';
+ if (forum_update_post($post,$message)) {
+
add_to_log($post->course, "forum", "update post",
"discuss.php?d=$post->discussion&parent=$post->id", "$post->id", $cm->id);
- $message = get_string("postupdated", "forum");
- $timemessage = 1;
-
+ $timemessage = 2;
+ if (!empty($message)) { // if we're printing stuff about the file upload
+ $timemessage = 4;
+ }
+ $message .= '
'.get_string("postupdated", "forum");
+
if ($subscribemessage = forum_post_subscription($post)) {
- $timemessage = 2;
+ $timemessage = 4;
}
redirect(forum_go_back_to("discuss.php?d=$post->discussion#$post->id"), $message.$subscribemessage, $timemessage);
@@ -62,13 +66,17 @@
exit;
} else if ($post->discussion) { // Adding a new post to an existing discussion
- if ($post->id = forum_add_new_post($post)) {
+ $message = '';
+ if ($post->id = forum_add_new_post($post,$message)) {
add_to_log($post->course, "forum", "add post",
"discuss.php?d=$post->discussion&parent=$post->id", "$post->id", $cm->id);
- $message = get_string("postadded", "forum", format_time($CFG->maxeditingtime));
$timemessage = 2;
+ if (!empty($message)) { // if we're printing stuff about the file upload
+ $timemessage = 4;
+ }
+ $message .= '
'.get_string("postadded", "forum", format_time($CFG->maxeditingtime));
if ($subscribemessage = forum_post_subscription($post)) {
$timemessage = 4;
@@ -85,14 +93,18 @@
$discussion = $post;
$discussion->name = $post->subject;
$discussion->intro = $post->message;
- if ($discussion->id = forum_add_discussion($discussion)) {
+ $message = '';
+ if ($discussion->id = forum_add_discussion($discussion,$message)) {
add_to_log($post->course, "forum", "add discussion",
"discuss.php?d=$discussion->id", "$discussion->id", $cm->id);
- $message = get_string("postadded", "forum", format_time($CFG->maxeditingtime));
$timemessage = 2;
-
+ if (!empty($message)) { // if we're printing stuff about the file upload
+ $timemessage = 4;
+ }
+ $message .= '
'.get_string("postadded", "forum", format_time($CFG->maxeditingtime));
+
if ($subscribemessage = forum_post_subscription($discussion)) {
$timemessage = 4;
}