"MDL-13766, removed debug code"
[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');
23require_once('lib.php');
51405677
PS
24
25require_login();
26admin_externalpage_setup('comments');
27
1bcb7eb5 28$context = get_context_instance(CONTEXT_SYSTEM);
29require_capability('moodle/comment:delete', $context);
51405677 30
985d1d1d
PS
31$PAGE->requires->yui2_lib('yahoo');
32$PAGE->requires->yui2_lib('dom');
33$PAGE->requires->yui2_lib('event');
34$PAGE->requires->yui2_lib('animation');
35$PAGE->requires->yui2_lib('json');
36$PAGE->requires->yui2_lib('connection');
9dec75db 37$PAGE->requires->js('/comment/admin.js');
1bcb7eb5 38
39$action = optional_param('action', '', PARAM_ALPHA);
40$commentid = optional_param('commentid', 0, PARAM_INT);
41$commentids = optional_param('commentids', '', PARAM_ALPHANUMEXT);
42$page = optional_param('page', 0, PARAM_INT);
51405677 43
1bcb7eb5 44$manager = new comment_manager();
45
51405677
PS
46if ($action and !confirm_sesskey()) {
47 // no action if sesskey not confirmed
48 $action = '';
1bcb7eb5 49}
50
51if ($action === 'delete') {
52 // delete a single comment
53 if (!empty($commentid)) {
54 if ($manager->delete_comment($commentid)) {
55 redirect($CFG->httpswwwroot.'/comment/', get_string('deleted'));
56 } else {
57 $err = 'cannotdeletecomment';
58 }
59 }
60 // delete a list of comments
61 if (!empty($commentids)) {
62 if ($manager->delete_comments($commentids)) {
63 die('yes');
64 } else {
65 die('no');
66 }
67 }
68}
69
1bcb7eb5 70admin_externalpage_print_header();
193a7a85 71echo $OUTPUT->heading(get_string('comments'));
1bcb7eb5 72if (!empty($err)) {
73 print_error($err, 'error', $CFG->httpswwwroot.'/comment/');
74}
75if (empty($action)) {
76 $manager->print_comments($page);
77 echo '<div class="mdl-align">';
78 echo '<button id="comments_delete">'.get_string('delete').'</button>';
8b5f5e81 79 echo '</div>';
1bcb7eb5 80}
7e0d6675 81echo $OUTPUT->footer();