2 // This file is part of Moodle - http://moodle.org/
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.
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);
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') {
46 $cmt->contextid
= $contextid;
47 $cmt->courseid
= $course->id
;
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)) {