weekly release 2.3dev
[moodle.git] / comment / index.php
CommitLineData
1bcb7eb5 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 */
21require_once('../config.php');
22require_once($CFG->libdir.'/adminlib.php');
c1951ea9 23require_once($CFG->dirroot.'/comment/locallib.php');
51405677
PS
24
25require_login();
367a75fa 26admin_externalpage_setup('comments', '', null, '', array('pagelayout'=>'report'));
51405677 27
1bcb7eb5 28$context = get_context_instance(CONTEXT_SYSTEM);
29require_capability('moodle/comment:delete', $context);
51405677 30
34e20eb4 31$PAGE->requires->js_init_call('M.core_comment.init_admin', null, true);
1bcb7eb5 32
33$action = optional_param('action', '', PARAM_ALPHA);
34$commentid = optional_param('commentid', 0, PARAM_INT);
35$commentids = optional_param('commentids', '', PARAM_ALPHANUMEXT);
36$page = optional_param('page', 0, PARAM_INT);
34e20eb4 37$confirm = optional_param('confirm', 0, PARAM_INT);
51405677 38
1bcb7eb5 39$manager = new comment_manager();
40
51405677
PS
41if ($action and !confirm_sesskey()) {
42 // no action if sesskey not confirmed
43 $action = '';
1bcb7eb5 44}
45
46if ($action === 'delete') {
47 // delete a single comment
48 if (!empty($commentid)) {
34e20eb4
DC
49 if (!$confirm) {
50 echo $OUTPUT->header();
51 $optionsyes = array('action'=>'delete', 'commentid'=>$commentid, 'confirm'=>1, 'sesskey'=>sesskey());
52 $optionsno = array('sesskey'=>sesskey());
53 $buttoncontinue = new single_button(new moodle_url('/comment/index.php', $optionsyes), get_string('delete'));
54 $buttoncancel = new single_button(new moodle_url('/comment/index.php', $optionsno), get_string('cancel'));
55 echo $OUTPUT->confirm(get_string('confirmdeletecomments', 'admin'), $buttoncontinue, $buttoncancel);
56 echo $OUTPUT->footer();
57 die;
1bcb7eb5 58 } else {
34e20eb4
DC
59 if ($manager->delete_comment($commentid)) {
60 redirect($CFG->httpswwwroot.'/comment/');
61 } else {
62 $err = 'cannotdeletecomment';
63 }
1bcb7eb5 64 }
65 }
66 // delete a list of comments
67 if (!empty($commentids)) {
68 if ($manager->delete_comments($commentids)) {
69 die('yes');
70 } else {
71 die('no');
72 }
73 }
74}
75
61ef8f9f 76echo $OUTPUT->header();
193a7a85 77echo $OUTPUT->heading(get_string('comments'));
34e20eb4 78echo $OUTPUT->box_start('generalbox commentsreport');
1bcb7eb5 79if (!empty($err)) {
80 print_error($err, 'error', $CFG->httpswwwroot.'/comment/');
81}
82if (empty($action)) {
34e20eb4 83 echo '<form method="post">';
c1951ea9
DC
84 $return = $manager->print_comments($page);
85 // if no comments available, $return will be false
86 if ($return) {
87 echo '<input type="submit" id="comments_delete" name="batchdelete" value="'.get_string('delete').'" />';
88 }
34e20eb4 89 echo '</form>';
1bcb7eb5 90}
34e20eb4
DC
91
92echo $OUTPUT->box_end();
7e0d6675 93echo $OUTPUT->footer();