$forum = $discussion->get_forum(); $cm = $forum->get_course_module(); $course = $forum->get_course(); // Check permission for change $discussion->require_edit(); // Is this the actual delete? if ($_SERVER['REQUEST_METHOD'] == 'POST') { if ($delete) { $discussion->delete(); redirect($forum->get_url(forum::PARAM_PLAIN)); } else { $discussion->undelete(); redirect('../../discuss.php?' . $discussion->get_link_params(forum::PARAM_PLAIN)); } } // Confirm page. Work out navigation for header $pagename = get_string($delete ? 'deletediscussion' : 'undeletediscussion', 'forumng', $discussion->get_subject(false)); $navigation = array(); $navigation[] = array('name' => shorten_text(htmlspecialchars($discussion->get_subject())), 'link' => $discussion->get_url(), 'type' => 'forumng'); $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(); // Show confirm option $confirmstring = get_string($delete ? 'confirmdeletediscussion' : 'confirmundeletediscussion', 'forumng'); notice_yesno($confirmstring, 'delete.php', '../../discuss.php', array('d' => $discussion->get_id(), 'delete' => $delete, 'clone' => $cloneid), array('d' => $discussion->get_id(), 'clone' => $cloneid), 'post', 'get'); // Display footer print_footer($course); } catch (forum_exception $e) { forum_utils::handle_exception($e); }
/** * This function handles all aspects of page processing and then calls * methods in $selector at the appropriate moments. * @param post_selector $selector Object that extends this base class */ static function go($selector) { $d = required_param('d', PARAM_INT); $cloneid = optional_param('clone', 0, PARAM_INT); $fromselect = optional_param('fromselect', 0, PARAM_INT); $all = optional_param('all', '', PARAM_RAW); $select = optional_param('select', '', PARAM_RAW); try { // Get basic objects $discussion = forum_discussion::get_from_id($d, $cloneid); if (optional_param('cancel', '', PARAM_RAW)) { // CALL TYPE 6 redirect('../../discuss.php?' . $discussion->get_link_params(forum::PARAM_PLAIN)); } $forum = $discussion->get_forum(); $cm = $forum->get_course_module(); $course = $forum->get_course(); $isform = optional_param('postselectform', 0, PARAM_INT); // Page name and permissions $pagename = $selector->get_page_name(); $buttonname = $selector->get_button_name(); $discussion->require_view(); $selector->require_capability($forum->get_context(), $discussion); if (!($fromselect || $isform || $all)) { // Either an initial request (non-JS) to display the 'dialog' box, // or a request to show the list of posts with checkboxes for // selection // Both types share same navigation $discussion->print_subpage_header($pagename); if (!$select) { // Show initial dialog print_box_start(); ?> <h2><?php print $buttonname; ?> </h2> <form action="<?php echo $_SERVER['PHP_SELF']; ?> " method="get"><div> <?php print $discussion->get_link_params(forum::PARAM_FORM); ?> <p><?php print_string('selectorall', 'forumng'); ?> </p> <div class="forumng-buttons"> <input type="submit" name="all" value="<?php print_string('discussion', 'forumng'); ?> " /> <input type="submit" name="select" value="<?php print_string('selectedposts', 'forumng'); ?> " /> </div> </div></form> <?php print_box_end(); } else { // Show list of posts to select ?> <div class="forumng-selectintro"> <p><?php print_string('selectintro', 'forumng'); ?> </p> </div> <form action="<?php echo $_SERVER['PHP_SELF']; ?> " method="post"><div> <?php print $discussion->get_link_params(forum::PARAM_FORM); ?> <input type="hidden" name="fromselect" value="1" /> <?php print $forum->get_type()->display_discussion($discussion, array(forum_post::OPTION_NO_COMMANDS => true, forum_post::OPTION_CHILDREN_EXPANDED => true, forum_post::OPTION_SELECTABLE => true)); ?> <div class="forumng-selectoutro"> <input type="submit" value="<?php print_string('confirmselection', 'forumng'); ?> " /> <input type="submit" name="cancel" value="<?php print_string('cancel'); ?> " /> </div> </div></form> <?php } // Display footer print_footer($course); } else { // Call types 3, 4, and 5 use the form (and may include list of postids) if ($all) { $postids = false; } else { $postids = array(); foreach ($_POST as $field => $value) { $matches = array(); if ((string) $value !== '0' && preg_match('~^selectp([0-9]+)$~', $field, $matches)) { $postids[] = $matches[1]; } } } // Get form to use $mform = $selector->get_form($discussion, $all, $postids); if (!$mform) { // Some options do not need a confirmation form; in that case, // just apply the action immediately. $selector->apply($discussion, $all, $postids, null); exit; } // Check cancel if ($mform->is_cancelled()) { redirect('../../discuss.php?' . $discussion->get_link_params(forum::PARAM_PLAIN)); } if ($fromform = $mform->get_data()) { // User submitted form to confirm process, which should now be // applied by selector. $selector->apply($discussion, $all, $postids, $fromform); exit; } else { $discussion->print_subpage_header($pagename); // User requested form either via JavaScript or the other way, and // either with all messages or the whole discussion. // Print form print $mform->display(); // Print optional content that goes after form print $selector->get_content_after_form($discussion, $all, $postids, $fromform); // Display footer print_footer($course); } } } catch (forum_exception $e) { forum_utils::handle_exception($e); } }