index.php 3.4 KB

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