Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/comment/comment_post.php
Go to the documentation of this file.
00001 <?php
00002 // This file is part of Moodle - http://moodle.org/
00003 //
00004 // Moodle is free software: you can redistribute it and/or modify
00005 // it under the terms of the GNU General Public License as published by
00006 // the Free Software Foundation, either version 3 of the License, or
00007 // (at your option) any later version.
00008 //
00009 // Moodle is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00016 
00017 /*
00018  * Handling new comments from non-js comments interface
00019  */
00020 require_once('../config.php');
00021 require_once($CFG->dirroot . '/comment/lib.php');
00022 
00023 if (empty($CFG->usecomments)) {
00024     throw new comment_exception('commentsnotenabled', 'moodle');
00025 }
00026 
00027 $contextid = optional_param('contextid', SYSCONTEXTID, PARAM_INT);
00028 list($context, $course, $cm) = get_context_info_array($contextid);
00029 
00030 require_login($course, true, $cm);
00031 require_sesskey();
00032 
00033 $action    = optional_param('action',    '',  PARAM_ALPHA);
00034 $area      = optional_param('area',      '',  PARAM_AREA);
00035 $content   = optional_param('content',   '',  PARAM_RAW);
00036 $itemid    = optional_param('itemid',    '',  PARAM_INT);
00037 $returnurl = optional_param('returnurl', '/', PARAM_URL);
00038 $component = optional_param('component', '',  PARAM_COMPONENT);
00039 
00040 // Currently this script can only add comments
00041 if ($action !== 'add') {
00042     redirect($returnurl);
00043 }
00044 
00045 $cmt = new stdClass;
00046 $cmt->contextid = $contextid;
00047 $cmt->courseid  = $course->id;
00048 $cmt->cm        = $cm;
00049 $cmt->area      = $area;
00050 $cmt->itemid    = $itemid;
00051 $cmt->component = $component;
00052 $comment = new comment($cmt);
00053 
00054 if ($comment->can_post()) {
00055     $cmt = $comment->add($content);
00056     if (!empty($cmt) && is_object($cmt)) {
00057         redirect($returnurl);
00058     }
00059 }
 All Data Structures Namespaces Files Functions Variables Enumerations