Skip to content

Commit

Permalink
Changed UI so users could not change tenant name once set
Browse files Browse the repository at this point in the history
  • Loading branch information
ADLMeganBohland committed Jun 14, 2024
1 parent 1f7b25f commit 786c4f6
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 180 deletions.
2 changes: 1 addition & 1 deletion lang/en/cmi5launch.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
$string['cmi5launchbasicname_default'] = '';

$string['cmi5launchtenantname'] = 'cmi5 player: The cmi5 tenant username.';
$string['cmi5launchtenantname_help'] = ' The tenant name attached to the token. Should only need to be used during initial setup. If for some reason the tenant name is changed a new bearer token will need to be generated.';
$string['cmi5launchtenantname_help'] = ' The tenant name attached to the token. Should only need to be used during initial setup. If for some reason the tenant name is changed a new bearer token will need to be generated. NOTE: changing a tenant name will require cmi5 launch link activites to need to be re-installed. Do not change name mid sessions! Data will be lost.';
$string['cmi5launchtenantname_default'] = '';

$string['cmi5launchbasepass'] = 'cmi5 player: basic password';
Expand Down
204 changes: 33 additions & 171 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,12 @@
?>

<script>

function myFunction() {
alert("I am an alert box!");
}

// Function for popup window.
function openprompt(){

console.log("I am in openprompt");

var site = prompt("Please enter the tenant name:", "The cmi5 tenant name. Please enter a name you would like to use");
if (site != null) {
// Set the form paramters.
// I wonder if I can just submit my own form again
$('#variableName').val(site);

// Post it.
Expand All @@ -59,92 +52,10 @@ function openprompt(){
}
function totokenpage(){

console.log("To the make a token page");


// Post it.
$('#settingformtoken').submit();


}
//TRy this new func
// Function for popup window
function openprompt3(){
//open a prompt box to get new tenant name for cmi5launch. Then we can call createtenant function
// Hold tenant name answer
var x;
var site = prompt("Please enter the tenant name:", "The cmi5 tenant name. Please enter a name you would like to use");
if (site != null) {

// document.getElementById("name").innerHTML = site;
//var p1 =encodeURIComponent(site);
var dataToSend = "variableName=" + (site);


////?????
var PageToSendTo = "settings.php";
var MyVariable = "variableData";
var VariablePlaceholder = "?variableName=";
var UrlToSend = PageToSendTo + VariablePlaceholder + encodeURIComponent(site);

// Prepare the data to send
var xhr = new XMLHttpRequest();

xhr.open("POST", "", true);
xhr.send(dataToSend);

// Create a new XMLHttpRequest object
//xhr.open("POST", "", true);

// Specify the request method, PHP script URL, and asynchronous
//xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

// Set the content type
xhr.onreadystatechange = function () {
if (xhr.readyState === XMLHttpRequest.DONE) {

console.log("where its going " + xhr.responseURL);
console.log("staus tect " + xhr.statusText);
// Check if the request is complete
if (xhr.status === 200) {

// Check if the request was successful
console.log(xhr.responseText);
// Output the response from the PHP script
} else {
console.error("Error:", xhr.status);
// Log an error if the request was unsuccessful
}

}

}
;
//xhr.send(dataToSend);
// Send the data to the PHP script
// //
// test it works and echo it
// console.log(site);
}
}


// Function for popup window
function openprompt2(){
//open a prompt box to get new tenant name for cmi5launch. Then we can call createtenant function
// Hold tenant name answer
var x;
var site = prompt("Please enter the tenant name:", "The cmi5 tenant name. Please enter a name you would like to use");
if (site != null) {

document.getElementById("name").innerHTML = site;
// //
// test it works and echo it
// console.log(site);
}
}


</script>
<?php

Expand All @@ -154,43 +65,6 @@ function openprompt2(){
require_once($CFG->dirroot . '/mod/cmi5launch/locallib.php');
require_once($CFG->dirroot . '/mod/cmi5launch/settingslib.php');

// Varibale to hold answer?
$nameanswer = "";


// Ok let's try to get the answer from the ajax method
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST["variableName"])) {
$receivedVariable = $_POST["variableName"];
echo "<br>";
echo" We got it ! it is ! : ". $receivedVariable;
echo " IGOT IT!";
// Process the received variable here
// Check for answer :
/////////// maybe come back to htis if (isset($_POST['tenantbutton'])) {

// Get the answer
// $.get('myFile.php', js_answer: answer);
// $nameanswer = $_POST['cmi5launchtenantname'];
// echo it
// echo $_POST["name"];
$sessionhelper = new cmi5_connectors;
$maketenant = $sessionhelper->cmi5launch_get_create_tenant();

// $pass = $_POST['tenantbutton'];

echo " What is recieved var : ";
echo $receivedVariable;
$newtenantname = $maketenant($receivedVariable);

echo $nameanswer;
}
// If it's null dont use it, if its not call func
if ($nameanswer != null) {
// Call func
echo" We got it ! it is ! : ". $nameanswer;
// $maketenant = $sessionhelper->cmi5launch_get_create_tenant();
}

// MB
// From scorm grading stuff.
$yesno = array(0 => get_string('no'),
Expand Down Expand Up @@ -247,21 +121,13 @@ function openprompt2(){
get_string('cmi5launchuseactoremail_help', 'cmi5launch'),
1));

// LEt's add a new header to separate cmi5 from lrs
$settings->add(new admin_setting_heading('cmi5launch/cmi5launchsettings', get_string('cmi5launchsettingsheader', 'cmi5launch'), ''));


$settings->add(new admin_setting_configtext_mod_cmi5launch('cmi5launch/cmi5launchplayerurl',
get_string('cmi5launchplayerurl', 'cmi5launch'),
get_string('cmi5launchplayerurl_help', 'cmi5launch'),
get_string('cmi5launchplayerurl_default', 'cmi5launch'), PARAM_URL));
/*
$settings->add(new admin_setting_configtext_mod_cmi5launch('cmi5launch/cmi5launchcontenturl',
get_string('cmi5launchcontenturl', 'cmi5launch'),
get_string('cmi5launchcontenturl_help', 'cmi5launch'),
get_string('cmi5launchcontenturl_default', 'cmi5launch'), PARAM_URL));
*/


$setting = new admin_setting_configtext('cmi5launch/cmi5launchbasicname',
get_string('cmi5launchbasicname', 'cmi5launch'),
Expand All @@ -276,15 +142,7 @@ function openprompt2(){
$settings->add($setting);



$warning = "OHNO";
// $link = "</form><a href=".new moodle_url('/settings.php')." class='btn btn-danger';>Empty all results</a> <strong style='color: red;'>".$warning."</strong>";
// $clear_url = new moodle_url('/settings.php');
// For form action we will call new tenant or new token
// Furthe we can set them as to apperar when made either here or in those funcs being called

// Info we need to send?
//$newtenantname;
// Buttons.
$linktotenant = "</br>
<p id=name >
<div class='input-group rounded'>
Expand All @@ -305,42 +163,46 @@ function openprompt2(){
";
//$link ="<a href='http://www.google.com' target='_parent'><button>Click me !</button></a>";

$setting = new admin_setting_configtext(
'cmi5launch/cmi5launchtenantname',
get_string('cmi5launchtenantname', 'cmi5launch'),
" " . get_string('cmi5launchtenantname_help', 'cmi5launch') . $linktotenant,
get_string('cmi5launchtenantname_default', 'cmi5launch')
);
$settings->add($setting);
/*
echo"<br>";
//echo "<script>document.writeln(p1);</script>";
//echo"Hey it worked and I cansee receivedVariable " . $receivedVariable;
echo "What is settings? Did we change it>???? ";
$toread = $settings['cmi5launchtenantname'];
var_dump($toread);
echo "<br>";
*/
// Verify there is a tenant name and id. If there is, display it, if not allow them to make one.
// Retrieves the string if there or false if not.
$tenantname = get_config('cmi5launch', 'cmi5launchtenantname');
$tenantid = get_config('cmi5launch', 'cmi5launchtenantid');

// If niether are false.
if ($tenantname != null && $tenantid != null) {

$todisplay = "<b>Tenant name is: " . $tenantname . ". Tenant id is: " . $tenantid . "</b><div><br> The tenant name and ID have been set. They cannot be changed without causing problems with existing cmi5 launch link activities. To change, plugin must be uninstalled and reinstalled.</div> <div><br></div>";
$setting = new admin_setting_description('cmi5launchtenantmessage', "cmi5launch tenant name and id:", $todisplay);
$settings->add($setting);

} else {

$setting = new admin_setting_configtext(
'cmi5launch/cmi5launchtenantname',
get_string('cmi5launchtenantname', 'cmi5launch'),
" " . get_string('cmi5launchtenantname_help', 'cmi5launch') . $linktotenant,
get_string('cmi5launchtenantname_default', 'cmi5launch')
);
$settings->add($setting);
};

$setting = new admin_setting_configtext('cmi5launch/cmi5launchtenanttoken',
get_string('cmi5launchtenanttoken', 'cmi5launch'),
get_string('cmi5launchtenanttoken_help', 'cmi5launch') . $linktotoken,
get_string('cmi5launchtenanttoken_default', 'cmi5launch'));
$settings->add($setting);

/*
$editstring = "I am a button";

$url = new moodle_url("$CFG->wwwroot/my/index.php");
$button = $OUTPUT->single_button($url, $editstring);
$PAGE->set_button($button);
$editstring2 = "I am another button";
$setting=
new admin_setting_configselect_with_lock(
'restore/restore_replace_keep_roles_and_enrolments',
new lang_string('setting_keep_roles_and_enrolments', 'backup'),
new lang_string('config_keep_roles_and_enrolments', 'backup'),
array('value' => 0, 'locked' => 0),
array(1 => get_string('yes'), 0 => get_string('no'))
);
$settings->add($setting);

$url = new moodle_url("$CFG->wwwroot/my/index.php");
$button = $OUTPUT->single_button($url, $editstring2);
$PAGE->set_button($button);
*/
// MB.
// Grade stuff I'm bringing over.
// Default grade settings.
Expand Down
2 changes: 1 addition & 1 deletion tenantsetup.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ function goback(){
}
} else {

echo "Failed to make tenant. Check connection to player and tenant name.";
echo "Failed to make tenant. Check connection to player and tenant name (cannot reuse old tenant names).";

echo $link;
}
Expand Down
12 changes: 5 additions & 7 deletions tokensetup.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ function goback(){
</div>
</p>";

// Maybe we can have a thing here if fromsettings equals a keyword, say token, call token making stuff.
// after all it doesn't need input from user. but we should write a catch to warn there is no tenant
// because it does need a tenant to make a token.

// Before a token can be made, there must be a tenant name and id, so verify these exist, if not throw error.

Expand All @@ -78,7 +75,7 @@ function goback(){
// If niether are false.
if ($tenantname != null && $tenantid != null) {

// Make the new tenant and grab results.
// Make the new token and grab results.
$token = $gettoken($tenantname, $tenantid);

// If the token is not false it should be what we need
Expand All @@ -92,7 +89,7 @@ function goback(){
echo "<br>";
echo "Save failed. With result " . $tokenresult . "<br>";

//if fail shoudl we freeze and alert user with a window towith error message
// If fail we freeze and alert user with a window with error message.
echo $link;
}else {
// Assumin the tokenresult is not false, it was saved correctly and we cango back to setting pae.
Expand All @@ -103,12 +100,13 @@ function goback(){
}
}
else {

echo "Failed to retrieve token from cmi5 player. Check connection with player, ensure tenant name and ID exist, and try again.";
echo "<br>";
echo "Token retrieval failed. With result " . $tokenresult . "<br>";

//if fail shoudl we freeze and alert user with a window towith error message
echo $link;
// If fail we freeze and alert user with a window with error message.
echo $link;
}

} else {
Expand Down

0 comments on commit 786c4f6

Please sign in to comment.