function finish($postid, $cloneid, $url, $fromform, $ajaxdata = '', $iframeredirect = false)
{
    global $ajax, $iframe;
    if ($ajax) {
        if ($ajaxdata) {
            // Print AJAX data if specified
            header('Content-Type: text/plain');
            print $ajaxdata;
            exit;
        } else {
            // Default otherwise is to print post
            mod_forumng_post::print_for_ajax_and_exit($postid, $cloneid, array(mod_forumng_post::OPTION_DISCUSSION_SUBJECT => true));
        }
    }
    if ($iframe) {
        if ($iframeredirect) {
            // Still redirect, even though it's in an iframe.
            redirect($url . '&iframe=1');
        } else {
            // Do not redirect, just output new post.
            mod_forumng_post::print_for_iframe_and_exit($postid, $cloneid, array(mod_forumng_post::OPTION_DISCUSSION_SUBJECT => true));
        }
    }
    redirect($url);
}
} else {
    if (!$post->can_undelete($whynot)) {
        print_error($whynot, 'forumng');
    }
}
// Is this the actual delete?
if ($_SERVER['REQUEST_METHOD'] == 'POST' && $email != 1) {
    // Delete or undelete the post
    if ($delete) {
        $post->delete();
    } else {
        $post->undelete();
    }
    // Redirect back
    if ($ajax) {
        mod_forumng_post::print_for_ajax_and_exit($postid, $cloneid);
    }
    // Only include post id if user can see deleted posts
    $postid = '';
    if (!$delete || has_capability('mod/forumng:editanypost', $forum->get_context())) {
        $postid = '#p' . $post->get_id();
    }
    redirect('discuss.php?' . $discussion->get_link_params(mod_forumng::PARAM_PLAIN) . $expandparam . $postid);
}
if ($email) {
    require_once 'deletepost_form.php';
    $urlparams = array('p' => $postid, 'delete' => $delete, 'email' => $email);
    if ($cloneid) {
        $urlparams['clone'] = $cloneid;
    }
    $url = new moodle_url("{$CFG->wwwroot}/mod/forumng/deletepost.php", $urlparams);
 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
require_once '../../config.php';
require_once 'mod_forumng.php';
// Post ID
$postid = required_param('p', PARAM_INT);
$cloneid = optional_param('clone', 0, PARAM_INT);
$raw = optional_param('raw', 0, PARAM_INT);
$pageparams = array('p' => $postid);
if ($cloneid) {
    $pageparams['clone'] = $cloneid;
}
if ($raw) {
    $pageparams['raw'] = $raw;
}
try {
    // Get post
    $post = mod_forumng_post::get_from_id($postid, $cloneid, true, true);
    // Do all access security checks
    $post->require_view();
    $post->get_discussion()->init_page(new moodle_url('/mod/forumng/expandpost.php', $pageparams), '');
    // Display post
    if ($raw) {
        print $post->prepare_edit_json();
    } else {
        mod_forumng_post::print_for_ajax_and_exit($post);
    }
} catch (coding_exception $e) {
    header('Content-Type: text/plain', true, 500);
    print $e->getMessage();
}