Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
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
 * prints the form so the user can fill out the feedback
19
 *
20
 * @author Andreas Grabs
21
 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
22
 * @package mod_feedback
23
 */
24
 
25
require_once("../../config.php");
26
require_once("lib.php");
27
 
28
$id = required_param('id', PARAM_INT);
29
$courseid = optional_param('courseid', null, PARAM_INT);
30
$gopage = optional_param('gopage', 0, PARAM_INT);
31
$gopreviouspage = optional_param('gopreviouspage', null, PARAM_RAW);
32
 
33
list($course, $cm) = get_course_and_cm_from_cmid($id, 'feedback');
34
$feedback = $DB->get_record("feedback", array("id" => $cm->instance), '*', MUST_EXIST);
35
 
36
$urlparams = array('id' => $cm->id, 'gopage' => $gopage, 'courseid' => $courseid);
37
$PAGE->set_url('/mod/feedback/complete.php', $urlparams);
38
 
39
require_course_login($course, true, $cm);
40
$PAGE->set_activity_record($feedback);
41
 
42
$context = context_module::instance($cm->id);
43
$feedbackcompletion = new mod_feedback_completion($feedback, $cm, $courseid);
44
 
45
$courseid = $feedbackcompletion->get_courseid();
46
 
47
// Check whether the feedback is mapped to the given courseid.
48
if (!has_capability('mod/feedback:edititems', $context) &&
49
        !$feedbackcompletion->check_course_is_mapped()) {
50
    echo $OUTPUT->header();
51
    echo $OUTPUT->notification(get_string('cannotaccess', 'mod_feedback'));
52
    echo $OUTPUT->footer();
53
    exit;
54
}
55
 
56
//check whether the given courseid exists
57
if ($courseid AND $courseid != SITEID) {
58
    require_course_login(get_course($courseid)); // This overwrites the object $COURSE .
59
}
60
 
61
if (!$feedbackcompletion->can_complete()) {
62
    throw new \moodle_exception('error');
63
}
64
 
65
$PAGE->navbar->add(get_string('feedback:complete', 'feedback'));
66
$PAGE->set_heading($course->fullname);
67
$PAGE->set_title($feedback->name);
68
$PAGE->set_pagelayout('incourse');
69
$PAGE->set_secondary_active_tab('modulepage');
70
$PAGE->add_body_class('limitedwidth');
71
 
72
// Check if the feedback is open (timeopen, timeclose).
73
if (!$feedbackcompletion->is_open()) {
74
    echo $OUTPUT->header();
75
    echo $OUTPUT->box_start('generalbox boxaligncenter');
76
    echo $OUTPUT->notification(get_string('feedback_is_not_open', 'feedback'));
77
    echo $OUTPUT->continue_button(course_get_url($courseid ?: $feedback->course));
78
    echo $OUTPUT->box_end();
79
    echo $OUTPUT->footer();
80
    exit;
81
}
82
 
83
// Mark activity viewed for completion-tracking.
84
if (isloggedin() && !isguestuser()) {
85
    $feedbackcompletion->set_module_viewed();
86
}
87
 
88
// Check if user is prevented from re-submission.
89
$cansubmit = $feedbackcompletion->can_submit();
90
 
91
// Initialise the form processing feedback completion.
92
if (!$feedbackcompletion->is_empty() && $cansubmit) {
93
    // Process the page via the form.
94
    $urltogo = $feedbackcompletion->process_page($gopage, $gopreviouspage);
95
 
96
    if ($urltogo !== null) {
97
        redirect($urltogo);
98
    }
99
}
100
 
101
// Print the page header.
102
$strfeedbacks = get_string("modulenameplural", "feedback");
103
$strfeedback  = get_string("modulename", "feedback");
104
 
105
echo $OUTPUT->header();
106
 
107
if ($feedbackcompletion->is_empty()) {
108
    \core\notification::error(get_string('no_items_available_yet', 'feedback'));
109
} else if ($cansubmit) {
110
    if ($feedbackcompletion->just_completed()) {
111
        // Display information after the submit.
112
        if ($feedback->page_after_submit) {
113
            echo $OUTPUT->box($feedbackcompletion->page_after_submit(),
114
                    'generalbox boxaligncenter');
115
        }
116
        if (!$PAGE->has_secondary_navigation() && $feedbackcompletion->can_view_analysis()) {
117
            echo '<p class="text-center">';
118
            $analysisurl = new moodle_url('/mod/feedback/analysis.php', array('id' => $cm->id, 'courseid' => $courseid));
119
            echo html_writer::link($analysisurl, get_string('completed_feedbacks', 'feedback'));
120
            echo '</p>';
121
        }
122
 
123
        if ($feedback->site_after_submit) {
124
            $url = feedback_encode_target_url($feedback->site_after_submit);
125
        } else {
126
            $url = course_get_url($courseid ?: $course->id);
127
        }
128
        echo $OUTPUT->continue_button($url);
129
    } else {
130
        // Display the form with the questions.
131
        echo $feedbackcompletion->render_items();
132
    }
133
} else {
134
    echo $OUTPUT->box_start('generalbox boxaligncenter');
1441 ariadna 135
    echo $OUTPUT->notification(
136
        get_string('this_feedback_is_already_submitted', 'feedback'),
137
        \core\output\notification::NOTIFY_INFO,
138
        closebutton: false,
139
    );
1 efrain 140
    echo $OUTPUT->continue_button(course_get_url($courseid ?: $course->id));
141
    echo $OUTPUT->box_end();
142
}
143
 
144
echo $OUTPUT->footer();