Merge branch 'MDL-32688-m22' of git://github.com/itamart/moodle into MOODLE_22_STABLE
[moodle.git] / comment / comment_post.php
blob4e852b4390033a2bcc92d7398d4137161524407b
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 * Handling new comments from non-js comments interface
20 require_once('../config.php');
21 require_once($CFG->dirroot . '/comment/lib.php');
23 if (empty($CFG->usecomments)) {
24 throw new comment_exception('commentsnotenabled', 'moodle');
27 $contextid = optional_param('contextid', SYSCONTEXTID, PARAM_INT);
28 list($context, $course, $cm) = get_context_info_array($contextid);
30 require_login($course, true, $cm);
31 require_sesskey();
33 $action = optional_param('action', '', PARAM_ALPHA);
34 $area = optional_param('area', '', PARAM_AREA);
35 $content = optional_param('content', '', PARAM_RAW);
36 $itemid = optional_param('itemid', '', PARAM_INT);
37 $returnurl = optional_param('returnurl', '/', PARAM_URL);
38 $component = optional_param('component', '', PARAM_COMPONENT);
40 // Currently this script can only add comments
41 if ($action !== 'add') {
42 redirect($returnurl);
45 $cmt = new stdClass;
46 $cmt->contextid = $contextid;
47 $cmt->courseid = $course->id;
48 $cmt->cm = $cm;
49 $cmt->area = $area;
50 $cmt->itemid = $itemid;
51 $cmt->component = $component;
52 $comment = new comment($cmt);
54 if ($comment->can_post()) {
55 $cmt = $comment->add($content);
56 if (!empty($cmt) && is_object($cmt)) {
57 redirect($returnurl);