MDL-21655 big scary enrolment and roles improvements - see tacker for list of changes...
[moodle.git] / comment / index.php
1 <?php
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/>.
18 /*
19  * Comments management interface
20  */
21 require_once('../config.php');
22 require_once($CFG->libdir.'/adminlib.php');
23 require_once('locallib.php');
25 require_login();
26 admin_externalpage_setup('comments');
28 $context = get_context_instance(CONTEXT_SYSTEM);
29 require_capability('moodle/comment:delete', $context);
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');
37 $PAGE->requires->js('/comment/admin.js');
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);
44 $manager = new comment_manager();
46 if ($action and !confirm_sesskey()) {
47     // no action if sesskey not confirmed
48     $action = '';
49 }
51 if ($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 }
70 admin_externalpage_print_header();
71 echo $OUTPUT->heading(get_string('comments'));
72 if (!empty($err)) {
73     print_error($err, 'error', $CFG->httpswwwroot.'/comment/');
74 }
75 if (empty($action)) {
76     $manager->print_comments($page);
77     echo '<div class="mdl-align">';
78     echo '<button id="comments_delete">'.get_string('delete').'</button>';
79     echo '</div>';
80 }
81 echo $OUTPUT->footer();