// Require discussion parameter here. Other parameters may be required in forum // type. $discussionid = required_param('d', PARAM_INT); $cloneid = optional_param('clone', 0, PARAM_INT); try { // Construct discussion variable (will check id is valid) // Retrieve new copy of discussion from database, but store it in cache // for further use. $discussion = forum_discussion::get_from_id($discussionid, $cloneid, 0, false, true); $forum = $discussion->get_forum(); $course = $forum->get_course(); $cm = $forum->get_course_module(); $context = $forum->get_context(); $draftid = optional_param('draft', 0, PARAM_INT); if ($draftid) { $draft = forum_draft::get_from_id($draftid); if (!$draft->is_reply() || $draft->get_discussion_id() != $discussionid) { print_error('draft_mismatch', 'forumng', $forum->get_url(forum::PARAM_HTML)); } $root = $discussion->get_root_post(); $inreplyto = $root->find_child($draft->get_parent_post_id(), false); if (!$inreplyto || !$inreplyto->can_reply($whynot) || !$discussion->can_view()) { print_error('draft_cannotreply', 'forumng', $forum->get_url(forum::PARAM_HTML), get_string($whynot, 'forumng')); } $inreplyto->force_expand(); $draftplayspaceid = 0; if ($draft->has_attachments()) { $draftplayspaceid = forum::create_attachment_playspace(); $target = forum::get_attachment_playspace_folder($draftplayspaceid); $source = $draft->get_attachment_folder(); foreach ($draft->get_attachment_names() as $name) {
/** * Obtains all draft posts in this forum by the given or current user, * in reverse date order. * @param int $userid User whose drafts will be retrieved. If zero, * retrieves draft for current user * @return array Array of forum_draft objects */ public function get_drafts($userid = 0) { $userid = forum_utils::get_real_userid($userid); return forum_draft::query_drafts("fdr.forumid = " . $this->get_id() . " AND fdr.userid = {$userid}"); }
<?php require_once '../../config.php'; require_once 'forum.php'; try { // Load draft and forum $draft = forum_draft::get_from_id(required_param('draft', PARAM_INT)); $forum = forum::get_from_id($draft->get_forum_id(), optional_param('clone', 0, PARAM_INT)); $course = $forum->get_course(); $cm = $forum->get_course_module(); // Check it belongs to current user if ($USER->id != $draft->get_user_id()) { print_error('draft_mismatch', 'forumng'); } // If they are actually deleting it, go ahead if ($_SERVER['REQUEST_METHOD'] == 'POST') { $draft->delete(); redirect($forum->get_url()); } // Confirm page. Work out navigation for header $pagename = get_string('deletedraft', 'forumng'); $navigation = array(); $navigation[] = array('name' => $pagename, 'type' => 'forumng'); $PAGEWILLCALLSKIPMAINDESTINATION = true; print_header_simple(format_string($forum->get_name()) . ': ' . $pagename, "", build_navigation($navigation, $cm), "", "", true, '', navmenu($course, $cm)); print skip_main_destination(); notice_yesno(get_string('confirmdeletedraft', 'forumng'), 'deletedraft.php', 'view.php', array('draft' => $draft->get_id()), array('id' => $cm->id), 'post', 'get'); print '<div class="forumng-post">'; print '<div class="forumng-1"></div>'; print '<div class="forumng-2"></div>'; print '<div class="forumng-pic">';
} if (isset($fromform->mailnow)) { $options->mailnow = $fromform->mailnow; } if (isset($fromform->setimportant)) { $options->setimportant = $fromform->setimportant; } $date = get_string('draftexists', 'forumng', forum_utils::display_date(time())); if ($draft) { // Update existing draft $draft->update(stripslashes($fromform->subject), stripslashes($fromform->message), $fromform->format, $deleteattachments, $attachments, $isdiscussion && $fromform->group ? $fromform->group : null, $options); // Redirect to edit it again finish(0, $cloneid, 'editpost.php?draft=' . $draft->get_id(), $fromform, $uploadfolder, $draft->get_id() . ':' . $date); } else { // Save new draft $newdraftid = forum_draft::save_new($forum, $isdiscussion ? $groupid : null, $replytoid ? $replytoid : null, stripslashes($fromform->subject), stripslashes($fromform->message), $fromform->format, $attachments, $options); // Redirect to edit it again finish(0, $cloneid, 'editpost.php?draft=' . $newdraftid, $fromform, $uploadfolder, $newdraftid . ':' . $date); } } else { if (!$edit) { // Check the random number is unique in session $random = optional_param('random', 0, PARAM_INT); if ($random) { if (!isset($SESSION->forumng_createdrandoms)) { $SESSION->forumng_createdrandoms = array(); } $now = time(); foreach ($SESSION->forumng_createdrandoms as $r => $then) { // Since this is meant to stop you clicking twice quickly, // expire anything older than 1 minute