Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
 
3
// This file is part of Moodle - http://moodle.org/
4
//
5
// Moodle is free software: you can redistribute it and/or modify
6
// it under the terms of the GNU General Public License as published by
7
// the Free Software Foundation, either version 3 of the License, or
8
// (at your option) any later version.
9
//
10
// Moodle is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
// GNU General Public License for more details.
14
//
15
// You should have received a copy of the GNU General Public License
16
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
17
 
18
/**
19
 * This file is responsible for saving the results of a users survey and displaying
20
 * the final message.
21
 *
22
 * @package   mod_survey
23
 * @copyright 1999 onwards Martin Dougiamas  {@link http://moodle.com}
24
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25
 */
26
 
27
    require_once('../../config.php');
28
    require_once('lib.php');
29
 
30
 
31
// Make sure this is a legitimate posting
32
 
33
    if (!$formdata = data_submitted() or !confirm_sesskey()) {
34
        throw new \moodle_exception('cannotcallscript');
35
    }
36
 
37
    $id = required_param('id', PARAM_INT);    // Course Module ID
38
 
39
    if (! $cm = get_coursemodule_from_id('survey', $id)) {
40
        throw new \moodle_exception('invalidcoursemodule');
41
    }
42
 
43
    if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
44
        throw new \moodle_exception('coursemisconf');
45
    }
46
 
47
    $PAGE->set_url('/mod/survey/save.php', array('id'=>$id));
48
    require_login($course, false, $cm);
49
 
50
    $context = context_module::instance($cm->id);
51
    require_capability('mod/survey:participate', $context);
52
 
53
    if (! $survey = $DB->get_record("survey", array("id"=>$cm->instance))) {
54
        throw new \moodle_exception('invalidsurveyid', 'survey');
55
    }
56
 
57
    $strsurveysaved = get_string('surveysaved', 'survey');
58
 
59
    $PAGE->set_title($strsurveysaved);
60
    $PAGE->set_heading($course->fullname);
61
    echo $OUTPUT->header();
62
    echo $OUTPUT->heading(format_string($survey->name));
63
 
64
    if (survey_already_done($survey->id, $USER->id)) {
65
        notice(get_string("alreadysubmitted", "survey"), get_local_referer(false));
66
        exit;
67
    }
68
 
69
    survey_save_answers($survey, $formdata, $course, $context);
70
 
71
// Print the page and finish up.
72
 
73
    notice(get_string("thanksforanswers","survey", $USER->firstname), "$CFG->wwwroot/course/view.php?id=$course->id");
74
 
75
    exit;
76
 
77
 
78