MDL-19793 Migrated calls to print_heading
[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');
24$context = get_context_instance(CONTEXT_SYSTEM);
25require_capability('moodle/comment:delete', $context);
26$PAGE->requires->yui_lib('yahoo')->in_head();
27$PAGE->requires->yui_lib('dom')->in_head();
28$PAGE->requires->yui_lib('event')->in_head();
29$PAGE->requires->yui_lib('animation')->in_head();
30$PAGE->requires->yui_lib('json')->in_head();
31$PAGE->requires->yui_lib('connection')->in_head();
32$PAGE->requires->js('comment/admin.js')->in_head();
33
34$action = optional_param('action', '', PARAM_ALPHA);
35$commentid = optional_param('commentid', 0, PARAM_INT);
36$commentids = optional_param('commentids', '', PARAM_ALPHANUMEXT);
37$page = optional_param('page', 0, PARAM_INT);
38$manager = new comment_manager();
39
40if (!empty($action)) {
41 confirm_sesskey();
42}
43
44if ($action === 'delete') {
45 // delete a single comment
46 if (!empty($commentid)) {
47 if ($manager->delete_comment($commentid)) {
48 redirect($CFG->httpswwwroot.'/comment/', get_string('deleted'));
49 } else {
50 $err = 'cannotdeletecomment';
51 }
52 }
53 // delete a list of comments
54 if (!empty($commentids)) {
55 if ($manager->delete_comments($commentids)) {
56 die('yes');
57 } else {
58 die('no');
59 }
60 }
61}
62
63admin_externalpage_setup('comments');
64admin_externalpage_print_header();
65print_heading(get_string('comments'));
66if (!empty($err)) {
67 print_error($err, 'error', $CFG->httpswwwroot.'/comment/');
68}
69if (empty($action)) {
70 $manager->print_comments($page);
71 echo '<div class="mdl-align">';
72 echo '<button id="comments_delete">'.get_string('delete').'</button>';
73 echo '<div>';
74}
75admin_externalpage_print_footer();