1 |
efrain |
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.
|
|
|
13 |
//
|
|
|
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/>.
|
|
|
16 |
|
|
|
17 |
/*
|
|
|
18 |
* Handling new comments from non-js comments interface
|
|
|
19 |
*
|
|
|
20 |
* @package core
|
|
|
21 |
* @copyright 2010 Dongsheng Cai {@link http://dongsheng.org}
|
|
|
22 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
23 |
*/
|
|
|
24 |
require_once('../config.php');
|
|
|
25 |
require_once($CFG->dirroot . '/comment/lib.php');
|
|
|
26 |
|
|
|
27 |
if (empty($CFG->usecomments)) {
|
|
|
28 |
throw new comment_exception('commentsnotenabled', 'moodle');
|
|
|
29 |
}
|
|
|
30 |
|
|
|
31 |
$contextid = optional_param('contextid', SYSCONTEXTID, PARAM_INT);
|
|
|
32 |
list($context, $course, $cm) = get_context_info_array($contextid);
|
|
|
33 |
|
|
|
34 |
require_login($course, true, $cm);
|
|
|
35 |
require_sesskey();
|
|
|
36 |
|
|
|
37 |
if (!$course) {
|
|
|
38 |
// Require_login() does not set context if called without a $course, do it manually.
|
|
|
39 |
$PAGE->set_context($context);
|
|
|
40 |
}
|
|
|
41 |
|
|
|
42 |
$action = optional_param('action', '', PARAM_ALPHA);
|
|
|
43 |
$area = optional_param('area', '', PARAM_AREA);
|
|
|
44 |
$content = optional_param('content', '', PARAM_RAW);
|
|
|
45 |
$itemid = optional_param('itemid', '', PARAM_INT);
|
|
|
46 |
$returnurl = optional_param('returnurl', '/', PARAM_LOCALURL);
|
|
|
47 |
$component = optional_param('component', '', PARAM_COMPONENT);
|
|
|
48 |
|
|
|
49 |
// Currently this script can only add comments
|
|
|
50 |
if ($action !== 'add') {
|
|
|
51 |
redirect($returnurl);
|
|
|
52 |
}
|
|
|
53 |
|
|
|
54 |
$cmt = new stdClass;
|
|
|
55 |
$cmt->contextid = $contextid;
|
|
|
56 |
if ($course) {
|
|
|
57 |
$cmt->courseid = $course->id;
|
|
|
58 |
}
|
|
|
59 |
$cmt->cm = $cm;
|
|
|
60 |
$cmt->area = $area;
|
|
|
61 |
$cmt->itemid = $itemid;
|
|
|
62 |
$cmt->component = $component;
|
|
|
63 |
$comment = new comment($cmt);
|
|
|
64 |
|
|
|
65 |
if ($comment->can_post()) {
|
|
|
66 |
$cmt = $comment->add($content);
|
|
|
67 |
if (!empty($cmt) && is_object($cmt)) {
|
|
|
68 |
redirect($returnurl);
|
|
|
69 |
}
|
|
|
70 |
}
|