diff --git a/mod/forum/lib.php b/mod/forum/lib.php index bc54e2217f7..63fed3d309f 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -96,12 +96,12 @@ function forum_add_instance($forum, $mform = null) { $discussion->id = forum_add_discussion($discussion, null, $message); if ($mform and $draftid = file_get_submitted_draft_itemid('introeditor')) { - // ugly hack - we need to copy the files somehow + // Ugly hack - we need to copy the files somehow. $discussion = $DB->get_record('forum_discussions', array('id'=>$discussion->id), '*', MUST_EXIST); $post = $DB->get_record('forum_posts', array('id'=>$discussion->firstpost), '*', MUST_EXIST); - $post->message = file_save_draft_area_files($draftid, $modcontext->id, 'mod_forum', 'post', $post->id, - mod_forum_post_form::attachment_options($forum), $post->message); + $options = array('subdirs'=>true); // Use the same options as intro field! + $post->message = file_save_draft_area_files($draftid, $modcontext->id, 'mod_forum', 'post', $post->id, $options, $post->message); $DB->set_field('forum_posts', 'message', $post->message, array('id'=>$post->id)); } } @@ -187,21 +187,19 @@ function forum_update_instance($forum, $mform) { $cm = get_coursemodule_from_instance('forum', $forum->id); $modcontext = context_module::instance($cm->id, MUST_EXIST); - if ($mform and $draftid = file_get_submitted_draft_itemid('introeditor')) { - // ugly hack - we need to copy the files somehow - $discussion = $DB->get_record('forum_discussions', array('id'=>$discussion->id), '*', MUST_EXIST); - $post = $DB->get_record('forum_posts', array('id'=>$discussion->firstpost), '*', MUST_EXIST); - - $post->message = file_save_draft_area_files($draftid, $modcontext->id, 'mod_forum', 'post', $post->id, - mod_forum_post_form::editor_options(), $post->message); - } - + $post = $DB->get_record('forum_posts', array('id'=>$discussion->firstpost), '*', MUST_EXIST); $post->subject = $forum->name; $post->message = $forum->intro; $post->messageformat = $forum->introformat; $post->messagetrust = trusttext_trusted($modcontext); $post->modified = $forum->timemodified; - $post->userid = $USER->id; // MDL-18599, so that current teacher can take ownership of activities + $post->userid = $USER->id; // MDL-18599, so that current teacher can take ownership of activities. + + if ($mform and $draftid = file_get_submitted_draft_itemid('introeditor')) { + // Ugly hack - we need to copy the files somehow. + $options = array('subdirs'=>true); // Use the same options as intro field! + $post->message = file_save_draft_area_files($draftid, $modcontext->id, 'mod_forum', 'post', $post->id, $options, $post->message); + } $DB->update_record('forum_posts', $post); $discussion->name = $forum->name; @@ -3327,7 +3325,13 @@ function forum_print_post($post, $discussion, $forum, &$cm, $course, $ownpost=fa if (!$post->parent && $forum->type == 'news' && $discussion->timestart > time()) { $age = 0; } - if (($ownpost && $age < $CFG->maxeditingtime) || $cm->cache->caps['mod/forum:editanypost']) { + + if ($forum->type == 'single' and $discussion->firstpost == $post->id) { + if (has_capability('moodle/course:manageactivities', $modcontext)) { + // The first post in single simple is the forum description. + $commands[] = array('url'=>new moodle_url('/course/modedit.php', array('update'=>$cm->id, 'sesskey'=>sesskey(), 'return'=>1)), 'text'=>$str->edit); + } + } else if (($ownpost && $age < $CFG->maxeditingtime) || $cm->cache->caps['mod/forum:editanypost']) { $commands[] = array('url'=>new moodle_url('/mod/forum/post.php', array('edit'=>$post->id)), 'text'=>$str->edit); } @@ -3335,7 +3339,9 @@ function forum_print_post($post, $discussion, $forum, &$cm, $course, $ownpost=fa $commands[] = array('url'=>new moodle_url('/mod/forum/post.php', array('prune'=>$post->id)), 'text'=>$str->prune, 'title'=>$str->pruneheading); } - if (($ownpost && $age < $CFG->maxeditingtime && $cm->cache->caps['mod/forum:deleteownpost']) || $cm->cache->caps['mod/forum:deleteanypost']) { + if ($forum->type == 'single' and $discussion->firstpost == $post->id) { + // Do not allow deleting of first post in single simple type. + } else if (($ownpost && $age < $CFG->maxeditingtime && $cm->cache->caps['mod/forum:deleteownpost']) || $cm->cache->caps['mod/forum:deleteanypost']) { $commands[] = array('url'=>new moodle_url('/mod/forum/post.php', array('delete'=>$post->id)), 'text'=>$str->delete); }