Merge branch 'MDL-26609-version-maturity' of git://github.com/mudrd8mz/moodle
[moodle.git] / comment / comment_post.php
blobe0730def927753a265a1ffe7123cec9891939a5a
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.
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/>.
19 * Handling new comments from non-js comments interface
21 require_once('../config.php');
22 require_once($CFG->dirroot . '/comment/lib.php');
24 $contextid = optional_param('contextid', SYSCONTEXTID, PARAM_INT);
25 list($context, $course, $cm) = get_context_info_array($contextid);
27 require_login($course, true, $cm);
28 require_sesskey();
30 $action = optional_param('action', '', PARAM_ALPHA);
31 $area = optional_param('area', '', PARAM_ALPHAEXT);
32 $commentid = optional_param('commentid', -1, PARAM_INT);
33 $content = optional_param('content', '', PARAM_RAW);
34 $itemid = optional_param('itemid', '', PARAM_INT);
35 $returnurl = optional_param('returnurl', '', PARAM_URL);
36 $component = optional_param('component', '', PARAM_ALPHAEXT);
38 $cmt = new stdClass();
39 $cmt->contextid = $contextid;
40 $cmt->courseid = $course->id;
41 $cmt->area = $area;
42 $cmt->itemid = $itemid;
43 $cmt->component = $component;
44 $comment = new comment($cmt);
46 switch ($action) {
47 case 'add':
48 $cmt = $comment->add($content);
49 if (!empty($cmt) && is_object($cmt)) {
50 redirect($returnurl);
52 break;
53 default:
54 exit;