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;
}
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";
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);
}
return $post->id;
}
-function forum_update_post($post) {
+function forum_update_post($post,&$message) {
$post->modified = time();
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);
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
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
}
} 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 .= '<br />'.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);
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 .= '<br />'.get_string("postadded", "forum", format_time($CFG->maxeditingtime));
if ($subscribemessage = forum_post_subscription($post)) {
$timemessage = 4;
$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 .= '<br />'.get_string("postadded", "forum", format_time($CFG->maxeditingtime));
+
if ($subscribemessage = forum_post_subscription($discussion)) {
$timemessage = 4;
}