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