From 786c4f6f0557418147afa265eafc21f391cb21a4 Mon Sep 17 00:00:00 2001 From: ADLMeganBohland Date: Fri, 14 Jun 2024 14:40:46 -0400 Subject: [PATCH] Changed UI so users could not change tenant name once set --- lang/en/cmi5launch.php | 2 +- settings.php | 204 +++++++---------------------------------- tenantsetup.php | 2 +- tokensetup.php | 12 +-- 4 files changed, 40 insertions(+), 180 deletions(-) diff --git a/lang/en/cmi5launch.php b/lang/en/cmi5launch.php index 484c12c..90064ab 100755 --- a/lang/en/cmi5launch.php +++ b/lang/en/cmi5launch.php @@ -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'; diff --git a/settings.php b/settings.php index 7a4e63c..2fbc097 100755 --- a/settings.php +++ b/settings.php @@ -37,19 +37,12 @@ ?> 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 "
"; - 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'), @@ -247,7 +121,6 @@ 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'), '')); @@ -255,13 +128,6 @@ function openprompt2(){ 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'), @@ -276,15 +142,7 @@ function openprompt2(){ $settings->add($setting); - -$warning = "OHNO"; - // $link = "Empty all results ".$warning.""; - // $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 = "

@@ -305,22 +163,28 @@ function openprompt2(){ "; //$link =""; - $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"
"; - //echo ""; - //echo"Hey it worked and I cansee receivedVariable " . $receivedVariable; - echo "What is settings? Did we change it>???? "; - $toread = $settings['cmi5launchtenantname']; - var_dump($toread); - echo "
"; -*/ + // 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 = "Tenant name is: " . $tenantname . ". Tenant id is: " . $tenantid . "

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.

"; + $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'), @@ -328,19 +192,17 @@ function openprompt2(){ 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. diff --git a/tenantsetup.php b/tenantsetup.php index 3a6f2f4..1300150 100644 --- a/tenantsetup.php +++ b/tenantsetup.php @@ -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; } diff --git a/tokensetup.php b/tokensetup.php index 789872f..ca30cc3 100644 --- a/tokensetup.php +++ b/tokensetup.php @@ -65,9 +65,6 @@ function goback(){

"; - // 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. @@ -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 @@ -92,7 +89,7 @@ function goback(){ echo "
"; echo "Save failed. With result " . $tokenresult . "
"; - //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. @@ -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 "
"; echo "Token retrieval failed. With result " . $tokenresult . "
"; - //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 {