MDL-19799 Migrated calls to print_heading
[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('lib.php');
24 $context = get_context_instance(CONTEXT_SYSTEM);
25 require_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();
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();
40 if (!empty($action)) {
41     confirm_sesskey();
42 }
44 if ($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 }
63 admin_externalpage_setup('comments');
64 admin_externalpage_print_header();
65 echo $OUTPUT->heading(get_string('comments'));
66 if (!empty($err)) {
67     print_error($err, 'error', $CFG->httpswwwroot.'/comment/');
68 }
69 if (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 }
75 admin_externalpage_print_footer();