-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathview.php
More file actions
129 lines (109 loc) · 4.34 KB
/
Copy pathview.php
File metadata and controls
129 lines (109 loc) · 4.34 KB
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
<?php
require(__DIR__.'/../../config.php');
require_once(__DIR__.'/lib.php');
require_once($CFG->dirroot.'/lib/externallib.php');
global $USER, $DB;
$id = optional_param('id', 0, PARAM_INT);
if ($id) {
$cm = get_coursemodule_from_id('chatbot', $id, 0, false, MUST_EXIST);
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
$chatbot = $DB->get_record('chatbot', array('id' => $cm->instance), '*', MUST_EXIST);
} else {
print_error('missingidandcmid', 'mod_chatbot');
}
require_login($course, true, $cm);
$context = context_module::instance($cm->id);
$userid = $USER->id;
$courseid = $course->id;
$service = $DB->get_record('external_services', array('shortname' => 'moodle_mobile_app'), '*');
if ($service) {
$token_record = $DB->get_record('external_tokens', array(
'userid' => $USER->id,
'externalserviceid' => $service->id,
'tokentype' => EXTERNAL_TOKEN_PERMANENT
));
if (!$token_record) {
$token_record = external_generate_token(
EXTERNAL_TOKEN_PERMANENT,
$service->id,
$USER->id,
context_system::instance(),
time() + 365 * 24 * 60 * 60
);
}
$moodle_token = $token_record->token;
error_log("CHATBOT DEBUG: Using Moodle token: " . substr($moodle_token, 0, 20) . "...");
} else {
$moodle_token = sesskey() . '_' . $USER->id;
error_log("CHATBOT DEBUG: Using sesskey fallback (service not found): " . substr($moodle_token, 0, 20) . "...");
}
$completion = new completion_info($course);
$completion->set_module_viewed($cm);
$PAGE->set_url('/mod/chatbot/view.php', array('id' => $cm->id));
$PAGE->set_title(format_string($chatbot->name));
$PAGE->set_heading(format_string($course->fullname));
$PAGE->set_context($context);
echo $OUTPUT->header();
echo $OUTPUT->heading(format_string($chatbot->name));
if ($chatbot->intro) {
echo $OUTPUT->box(format_module_intro('chatbot', $chatbot, $cm->id), 'generalbox', 'intro');
}
$iframe_url = 'https://moodle-edu-chatbot.vercel.app/';
$iframe_params = array(
'token' => $moodle_token,
'courseid' => $courseid,
'coursename' => $course->fullname
);
$iframe_src = new moodle_url($iframe_url, $iframe_params);
echo html_writer::start_div('chatbot-container', array('style' => 'position: relative;', 'id' => 'chatbot-wrapper'));
echo html_writer::tag('button', '⛶ ' . get_string('fullscreen', 'chatbot'), array(
'id' => 'fullscreen-btn',
'class' => 'btn btn-secondary btn-sm',
'title' => get_string('fullscreentitle', 'chatbot'),
'style' => 'position: absolute; top: 10px; right: 10px; z-index: 1000;'
));
echo html_writer::tag('iframe', '', array(
'src' => $iframe_src->out(false),
'width' => '100%',
'height' => '700px',
'style' => 'border: 1px solid #dee2e6; border-radius: 0.25rem;',
'title' => get_string('pluginname', 'chatbot'),
'class' => 'chatbot-iframe',
'id' => 'chatbot-iframe',
'allowfullscreen' => 'true'
));
echo html_writer::end_div();
echo html_writer::tag('script', "
var fullscreenText = '" . get_string('fullscreen', 'chatbot') . "';
var exitFullscreenText = '" . get_string('exitfullscreen', 'chatbot') . "';
document.getElementById('fullscreen-btn').addEventListener('click', function() {
var wrapper = document.getElementById('chatbot-wrapper');
var iframe = document.getElementById('chatbot-iframe');
if (!document.fullscreenElement) {
if (wrapper.requestFullscreen) {
wrapper.requestFullscreen();
} else if (wrapper.webkitRequestFullscreen) {
wrapper.webkitRequestFullscreen();
} else if (wrapper.msRequestFullscreen) {
wrapper.msRequestFullscreen();
}
iframe.style.height = '100vh';
this.textContent = '✕ ' + exitFullscreenText;
} else {
if (document.exitFullscreen) {
document.exitFullscreen();
}
iframe.style.height = '700px';
this.textContent = '💬 ' + fullscreenText;
}
});
document.addEventListener('fullscreenchange', function() {
var iframe = document.getElementById('chatbot-iframe');
var btn = document.getElementById('fullscreen-btn');
if (!document.fullscreenElement) {
iframe.style.height = '700px';
btn.textContent = '💬 ' + fullscreenText;
}
});
", array('type' => 'text/javascript'));
echo $OUTPUT->footer();