/** * If successful, this function returns the name of the file * * @global object * @param object $post is a full post record, including course and forum * @param object $forum * @param object $cm * @param mixed $mform * @param string $unused * @return bool */ function forum_add_attachment($post, $forum, $cm, $mform=null, $unused=null) { global $DB; if (empty($mform)) { return false; } if (empty($post->attachments)) { return true; // Nothing to do } $context = context_module::instance($cm->id); $info = file_get_draft_area_info($post->attachments); $present = ($info['filecount']>0) ? '1' : ''; file_save_draft_area_files($post->attachments, $context->id, 'mod_forum', 'attachment', $post->id, mod_forum_post_form::attachment_options($forum)); $DB->set_field('forum_posts', 'attachment', $present, array('id'=>$post->id)); return true; }
print_error('invalidcoursemodule'); } $modcontext = context_module::instance($cm->id); require_login($course, false, $cm); if (isguestuser()) { // just in case print_error('noguest'); } if (!isset($forum->maxattachments)) { // TODO - delete this once we add a field to the forum table $forum->maxattachments = 3; } $thresholdwarning = forum_check_throttling($forum, $cm); $mform_post = new mod_forum_post_form('post.php', array('course' => $course, 'cm' => $cm, 'coursecontext' => $coursecontext, 'modcontext' => $modcontext, 'forum' => $forum, 'post' => $post, 'subscribe' => \mod_forum\subscriptions::is_subscribed($USER->id, $forum, null, $cm), 'thresholdwarning' => $thresholdwarning, 'edit' => $edit), 'post', '', array('id' => 'mformforum')); $draftitemid = file_get_submitted_draft_itemid('attachments'); file_prepare_draft_area($draftitemid, $modcontext->id, 'mod_forum', 'attachment', empty($post->id) ? null : $post->id, mod_forum_post_form::attachment_options($forum)); //load data into form NOW! if ($USER->id != $post->userid) { // Not the original author, so add a message to the end $data = new stdClass(); $data->date = userdate($post->modified); if ($post->messageformat == 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) . ')'; } unset($data); } $formheading = '';