-
Notifications
You must be signed in to change notification settings - Fork 1
/
confirmation.php
111 lines (100 loc) · 4.66 KB
/
confirmation.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Confirmation Buttons page which is used in an iframe in the module description.
*
* @package mod_consentform
* @copyright 2020 Thomas Niedermaier, Medical University of Vienna <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(__DIR__ . '/../../config.php');
require_once(dirname(__FILE__) . '/locallib.php');
$id = optional_param('id', 0, PARAM_INT); // Instance ID.
$consentform = $DB->get_record('consentform', array('id' => $id), '*', MUST_EXIST);
list($course, $cm) = get_course_and_cm_from_instance($id, 'consentform', $consentform->course);
require_login($course, false, $cm);
$context = context_module::instance($cm->id);
// Agreement form, participant's view.
$mform = new \mod_consentform\consentform_agreement_form(null,
array('id' => $id,
'cmid' => $cm->id,
'courseid' => $course->id,
'consentform' => $consentform,
'userid' => $USER->id,
'confirmationtextclass' => 'consentform_confirmationtext_incourseoverview'
));
// Process participant's agreement form data and redirect.
if ($data = $mform->get_data()) {
$PAGE->set_url('/mod/consentform/confirmation.php', array('id' => $cm->id));
$PAGE->set_title(format_string($consentform->name));
$PAGE->set_pagelayout('embedded');
if (isset( $data->agreement) && $data->agreement == $consentform->textagreementbutton) {
$ok = consentform_save_agreement(EXPECTEDCOMPLETIONVALUE, $USER->id, $cm->id);
$message = get_string('msgagreed', 'consentform');
$event = \mod_consentform\event\agreement_agree::create(
array(
'objectid' => $PAGE->cm->id,
'context' => $PAGE->context
)
);
} else if (isset($data->revocation) && $data->revocation == $consentform->textrevocationbutton) {
$ok = consentform_save_agreement(CONSENTFORM_STATUS_REVOKED, $USER->id, $cm->id);
$message = get_string('msgrevoked', 'consentform');
$event = \mod_consentform\event\agreement_revoke::create(
array(
'objectid' => $PAGE->cm->id,
'context' => $PAGE->context
)
);
} else if (isset($data->refusal) && $data->refusal == $consentform->textrefusalbutton) {
$ok = consentform_save_agreement(CONSENTFORM_STATUS_REFUSED, $USER->id, $cm->id);
$message = get_string('msgrefused', 'consentform');
$event = \mod_consentform\event\agreement_refuse::create(
array(
'objectid' => $PAGE->cm->id,
'context' => $PAGE->context
)
);
}
$event->trigger();
$redirecturl = new moodle_url('/mod/consentform/confirmation.php', array('id' => $id));
$SESSION->consentform_reloadiframe = "1";
redirect($redirecturl);
} else { // No data from form.
if (isset($SESSION->consentform_reloadiframe)) {
unset($SESSION->consentform_reloadiframe);
// Reload parent after form processing.
echo html_writer::script('parent.location.reload();');
} else {
// Show inline form only if there is no user's action yet.
if (!$DB->record_exists(
'consentform_state', array('consentformcmid' => $cm->id, 'userid' => $USER->id))) {
// Display agreement form to participant.
$PAGE->set_url('/mod/consentform/confirmation.php', array('id' => $cm->id));
$PAGE->set_title(format_string($consentform->name));
$PAGE->set_pagelayout('embedded');
echo $OUTPUT->header();
echo $OUTPUT->box_start('', 'consentform_main_cointainer');
$mform->display();
echo $OUTPUT->box_end();
} else {
$jscode = "window.onload=function(){var myIframe;if (myIframe = window.parent.document.getElementsByName('";
$jscode .= "consentformiframe$consentform->id')[0]) {";
$jscode .= "myIframe.remove();}}";
echo html_writer::script($jscode);
}
}
}