forked from udima-university/moodle-mod_jitsi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
formuniversal.php
168 lines (152 loc) · 6.07 KB
/
formuniversal.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<?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/>.
/**
* Prints a particular instance of jitsi
*
* You can have a rather longer description of the file as well,
* if you like, and it can span multiple lines.
*
* @package mod_jitsi
* @copyright 2021 Sergio Comerón <sergiocomeron@icloud.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
require_once(dirname(dirname(dirname(__FILE__))).'/lib/moodlelib.php');
require_once(dirname(__FILE__).'/lib.php');
require_once("$CFG->libdir/formslib.php");
global $DB;
$token = required_param('t', PARAM_TEXT);
$sql = "select * from {jitsi} where token = '".$token."'";
$jitsi = $DB->get_record_sql($sql);
$module = $DB->get_record ('modules', ['name' => 'jitsi']);
$cm = $DB->get_record ('course_modules', ['instance' => $jitsi->id, 'module' => $module->id]);
$id = $cm->id;
$sessionid = $cm->instance;
/**
* Access form for name.
*/
class name_form extends moodleform {
/**
* Define the form
*/
public function definition() {
global $CFG, $USER;
$mform = $this->_form;
$mform->addElement('text', 'name', get_string('name'));
$mform->setType('name', PARAM_TEXT);
$mform->addRule('name', get_string('required'), 'required', '', 'client', false, false);
$buttonarray = [];
$buttonarray[] = $mform->createElement('submit', 'submitbutton', get_string('continue'));
$mform->addGroup($buttonarray, 'buttonar', '', ' ', false);
}
/**
* Validate the form data
*
* @param array $data array of ("fieldname"=>value) of submitted data
* @param array $files array of uploaded files "element_name"=>tmp_file_path
* @return array of "element_name"=>"error_description" if there are errors,
* or an empty array if everything is OK (true allowed for backwards compatibility too).
*/
public function validation($data, $files) {
return [];
}
}
$PAGE->set_url($CFG->wwwroot.'/mod/jitsi/formuniversal.php');
$sesion = $DB->get_record('jitsi', ['id' => $sessionid]);
$PAGE->set_cm($cm);
$PAGE->set_context(context_module::instance($id));
$PAGE->set_title(get_string('accesstotitle', 'jitsi', $sesion->name));
$PAGE->set_heading(get_string('accesstotitle', 'jitsi', $sesion->name));
echo $OUTPUT->header();
if ($jitsi->intro && $CFG->branch < 40) {
echo $jitsi->intro;
}
$event = \mod_jitsi\event\jitsi_session_guest_form::create([
'objectid' => $PAGE->cm->instance,
'context' => $PAGE->context,
]);
$event->add_record_snapshot('course', $PAGE->course);
$event->add_record_snapshot($PAGE->cm->modname, $sesion);
$event->trigger();
if (!istimedout($sesion)) {
if ($CFG->jitsi_invitebuttons == 1) {
if (!isloggedin()) {
echo get_string('accessto', 'jitsi', $sesion->name);
$today = getdate();
if ($today[0] < $sesion->timeclose || $sesion->timeclose == 0) {
if ($today[0] > (($sesion->timeopen) - ($sesion->minpretime * 60))) {
$urlparamsform = ['ses' => $sessionid, 'id' => $id];
$urlform = new moodle_url('/mod/jitsi/universal.php', $urlparamsform);
$mform = new name_form($urlform);
if ($mform->is_cancelled()) {
echo "";
} else if ($fromform = $mform->get_data()) {
echo "";
} else {
$mform->display();
}
} else {
echo $OUTPUT->box(get_string('nostart', 'jitsi',
date("d-m-Y H:i", ($sesion->timeopen - ($sesion->minpretime * 60)))));
}
} else {
echo $OUTPUT->box(get_string('finish', 'jitsi'));
}
} else {
echo get_string('accesstowithlogin', 'jitsi', $sesion->name);
$today = getdate();
if ($today[0] > (($sesion->timeopen) - ($sesion->minpretime * 60))) {
$nom = null;
switch ($CFG->jitsi_id) {
case 'username':
$nom = $USER->username;
break;
case 'nameandsurname':
$nom = $USER->firstname.' '.$USER->lastname;
break;
case 'alias':
break;
}
$avatar = $CFG->wwwroot.'/user/pix.php/'.$USER->id.'/f1.jpg';
$mail = '';
$urlparams = [
'avatar' => $avatar,
'name' => $nom,
'ses' => $sessionid,
'mail' => $mail,
'id' => $id,
];
echo $OUTPUT->box(get_string('instruction', 'jitsi'));
echo $OUTPUT->single_button(new moodle_url('/mod/jitsi/universal.php', $urlparams),
get_string('access', 'jitsi'), 'post');
} else {
echo $OUTPUT->box(get_string('nostart', 'jitsi',
date("d-m-Y H:i", ($sesion->timeopen - ($sesion->minpretime * 60)))));
}
}
} else {
echo get_string('noinviteaccess', 'jitsi');
}
} else {
echo "<div class=\"alert alert-danger\" role=\"alert\">";
echo generateerrortime($sesion);
echo "</div>";
}
echo '<p></p>';
echo $CFG->jitsi_help;
if (isloggedin()) {
echo $OUTPUT->footer();
}