-
Notifications
You must be signed in to change notification settings - Fork 6
/
setup.php
127 lines (94 loc) · 3.93 KB
/
setup.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
<?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/>.
/**
* This page is a setup page to compliment settings and enable a user to commuicate with cmi5 player for tenant issues.
*
* @copyright 2023 Megan Bohland
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
use mod_cmi5launch\local\cmi5_connectors;
?>
<script>
// Function to go back to settings page.
function goback(){
//REtrieve and submit form
let input = document.getElementById('gobackform');
input.submit();
}
</script>
<?php
require_once(dirname(dirname(dirname(__FILE__))) . '/config.php');
require_once($CFG->libdir.'/tablelib.php');
require_once($CFG->dirroot.'/mod/cmi5launch/locallib.php');
require_once($CFG->libdir.'/formslib.php');
require_once($CFG->dirroot. '/reportbuilder/classes/local/report/column.php');
define('CMI5LAUNCH_REPORT_DEFAULT_PAGE_SIZE', 20);
define('CMI5LAUNCH_REPORT_ATTEMPTS_ALL_STUDENTS', 0);
define('CMI5LAUNCH_REPORT_ATTEMPTS_STUDENTS_WITH', 1);
define('CMI5LAUNCH_REPORT_ATTEMPTS_STUDENTS_WITH_NO', 2);
$PAGE->requires->jquery();
global $cmi5launch, $CFG;
// External classes and functions.
$cmi5helper = new cmi5_connectors;
$createtenant = $cmi5helper->cmi5launch_get_create_tenant();
// Retrieve the name entered in previous pages prompt. This will be the new tenant name.
$fromsettings = required_param('variableName', PARAM_TEXT);
// Button to return to settings page.
$link = "</br>
<p id=name >
<div class='input-group rounded'>
<button class='btn btn-secondary' name='tenantbutton' onclick='goback()'>
<span class='button-label'>Ok</span>
</button>
</div>
</p>";
// Ensure a name was entered.
if ($fromsettings != null) {
// Make the new tenant and grab results.
$tenant = $createtenant($fromsettings);
// The return response should be an array and have 'id' and 'code'
$response = $tenant;
//Do we need an if statement for response tyopo?
$name = $response['code'];
$id = $response['id'];
// maybe if we make the button link thing here and then just echo it we can save on repetitive code.
// if we have a response, we can save the tenant name to the settings
if ($name != null && $id != null) {
// Save the tenant name to the settings
$result = set_config('cmi5launchtenantname', $name, $plugin = 'cmi5launch');
if ($result) {
echo "Successfully made and saved new tenant";
echo "Tenant name: " . $name . "<br>";
echo "Tenant ID: " . $id . "<br>";
//Hopefully that worked? Now back to settings
$settingurl = new moodle_url($CFG->wwwroot . '/' . 'admin/settings.php', array('section' => 'modsettingcmi5launch'));
} else {
echo "Failed to make tenant. Check connection to player and tenant name.";
//if fail shoudl we freeze and alert user with a window towith error message
echo $link;
}
} else {
echo "Tenant name not retrieved from player. Check connection.";
echo $link;
}
} else {
echo "Tenant name not retrieved or blank. Please try again.";
echo $link;
}
?>
<form id="gobackform" action="../../admin/settings.php" method="get">
<input id="section" name="section" type="hidden" value="modsettingcmi5launch">
</form>