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 |
* Handles clicking of the submit button in the Course Ratings block.
|
|
|
19 |
*
|
|
|
20 |
* @package block
|
|
|
21 |
* @subpackage rate_course
|
|
|
22 |
* @copyright 2009 Jenny Gray
|
|
|
23 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
24 |
*
|
|
|
25 |
* Code was Rewritten for Moodle 2.X By Atar + Plus LTD for Comverse LTD.
|
|
|
26 |
* @copyright © 2011 Comverse LTD.
|
|
|
27 |
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
|
|
28 |
*/
|
|
|
29 |
|
|
|
30 |
require_once("../../config.php");
|
|
|
31 |
|
|
|
32 |
$id = required_param('id', PARAM_INT); // Course Module ID.
|
|
|
33 |
$grade = required_param('grade', PARAM_INT); // User selection.
|
|
|
34 |
|
|
|
35 |
if (! $course = $DB->get_record("course", array("id"=>$id))) {
|
|
|
36 |
error("Course ID not found");
|
|
|
37 |
}
|
|
|
38 |
|
|
|
39 |
require_login($course, false);
|
|
|
40 |
if (!$context = get_context_instance(CONTEXT_COURSE, $course->id)) {
|
|
|
41 |
print_error('nocontext');
|
|
|
42 |
}
|
|
|
43 |
|
|
|
44 |
require_capability('block/rate_course:rate', $context);
|
|
|
45 |
global $USER;
|
|
|
46 |
|
|
|
47 |
if ($form = data_submitted()) {
|
|
|
48 |
if ($DB->count_records('block_rate_course',
|
|
|
49 |
array('course'=>$COURSE->id, 'userid'=>$USER->id))) {
|
|
|
50 |
print_error('completed', 'block_rate_course');
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
$completion = new stdClass;
|
|
|
54 |
$completion->course = $COURSE->id;
|
|
|
55 |
$completion->userid = $USER->id;
|
|
|
56 |
$completion->rating = $grade;
|
|
|
57 |
$DB->insert_record( 'block_rate_course', $completion );
|
|
|
58 |
|
|
|
59 |
redirect($CFG->wwwroot.'/course/view.php?id='.$COURSE->id);
|
|
|
60 |
|
|
|
61 |
}
|