Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.
/comment/ -> index.php (source)

Differences Between: [Versions 39 and 311] [Versions 39 and 400] [Versions 39 and 401] [Versions 39 and 402] [Versions 39 and 403]

   1  <?php
   2  
   3  // This file is part of Moodle - http://moodle.org/
   4  //
   5  // Moodle is free software: you can redistribute it and/or modify
   6  // it under the terms of the GNU General Public License as published by
   7  // the Free Software Foundation, either version 3 of the License, or
   8  // (at your option) any later version.
   9  //
  10  // Moodle is distributed in the hope that it will be useful,
  11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13  // GNU General Public License for more details.
  14  //
  15  // You should have received a copy of the GNU General Public License
  16  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  17  
  18  /*
  19   * Comments management interface
  20   *
  21   * @package   core
  22   * @copyright 2010 Dongsheng Cai {@link http://dongsheng.org}
  23   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  require_once('../config.php');
  26  require_once($CFG->libdir.'/adminlib.php');
  27  require_once($CFG->dirroot.'/comment/locallib.php');
  28  
  29  admin_externalpage_setup('comments', '', null, '', array('pagelayout'=>'report'));
  30  
  31  $context = context_system::instance();
  32  require_capability('moodle/comment:delete', $context);
  33  
  34  $PAGE->requires->js_init_call('M.core_comment.init_admin', null, true);
  35  
  36  $action     = optional_param('action', '', PARAM_ALPHA);
  37  $commentid  = optional_param('commentid', 0, PARAM_INT);
  38  $commentids = optional_param('commentids', '', PARAM_ALPHANUMEXT);
  39  $page       = optional_param('page', 0, PARAM_INT);
  40  $confirm    = optional_param('confirm', 0, PARAM_INT);
  41  
  42  $manager = new comment_manager();
  43  
  44  if ($action and !confirm_sesskey()) {
  45      // no action if sesskey not confirmed
  46      $action = '';
  47  }
  48  
  49  if ($action === 'delete') {
  50      // delete a single comment
  51      if (!empty($commentid)) {
  52          if (!$confirm) {
  53              echo $OUTPUT->header();
  54              $optionsyes = array('action'=>'delete', 'commentid'=>$commentid, 'confirm'=>1, 'sesskey'=>sesskey());
  55              $optionsno  = array('sesskey'=>sesskey());
  56              $buttoncontinue = new single_button(new moodle_url('/comment/index.php', $optionsyes), get_string('delete'));
  57              $buttoncancel = new single_button(new moodle_url('/comment/index.php', $optionsno), get_string('cancel'));
  58              echo $OUTPUT->confirm(get_string('confirmdeletecomments', 'admin'), $buttoncontinue, $buttoncancel);
  59              echo $OUTPUT->footer();
  60              die;
  61          } else {
  62              if ($manager->delete_comment($commentid)) {
  63                  redirect($CFG->wwwroot.'/comment/');
  64              } else {
  65                  $err = 'cannotdeletecomment';
  66              }
  67          }
  68      }
  69      // delete a list of comments
  70      if (!empty($commentids)) {
  71          if ($manager->delete_comments($commentids)) {
  72              die('yes');
  73          } else {
  74              die('no');
  75          }
  76      }
  77  }
  78  
  79  echo $OUTPUT->header();
  80  echo $OUTPUT->heading(get_string('comments'));
  81  echo $OUTPUT->box_start('generalbox commentsreport');
  82  if (!empty($err)) {
  83      print_error($err, 'error', $CFG->wwwroot.'/comment/');
  84  }
  85  if (empty($action)) {
  86      echo '<form method="post">';
  87      $return = $manager->print_comments($page);
  88      // if no comments available, $return will be false
  89      if ($return) {
  90          echo '<input type="submit" class="btn btn-primary" id="comments_delete" name="batchdelete"
  91              value="'.get_string('delete').'" />';
  92      }
  93      echo '</form>';
  94  }
  95  
  96  echo $OUTPUT->box_end();
  97  echo $OUTPUT->footer();