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
21 * @copyright 2010 Dongsheng Cai {@link http://dongsheng.org}
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 require_once('../config.php');
25 require_once($CFG->dirroot
. '/comment/lib.php');
27 if (empty($CFG->usecomments
)) {
28 throw new comment_exception('commentsnotenabled', 'moodle');
31 $contextid = optional_param('contextid', SYSCONTEXTID
, PARAM_INT
);
32 list($context, $course, $cm) = get_context_info_array($contextid);
34 require_login($course, true, $cm);
37 $action = optional_param('action', '', PARAM_ALPHA
);
38 $area = optional_param('area', '', PARAM_AREA
);
39 $content = optional_param('content', '', PARAM_RAW
);
40 $itemid = optional_param('itemid', '', PARAM_INT
);
41 $returnurl = optional_param('returnurl', '/', PARAM_URL
);
42 $component = optional_param('component', '', PARAM_COMPONENT
);
44 // Currently this script can only add comments
45 if ($action !== 'add') {
50 $cmt->contextid
= $contextid;
51 $cmt->courseid
= $course->id
;
54 $cmt->itemid
= $itemid;
55 $cmt->component
= $component;
56 $comment = new comment($cmt);
58 if ($comment->can_post()) {
59 $cmt = $comment->add($content);
60 if (!empty($cmt) && is_object($cmt)) {