Index: moodle/mod/lamslesson/lang/en/lamslesson.php =================================================================== diff -u -r606bc0215a34c4af3f93611e71553d8020d47036 -rfff4221d477dd2d8bbac61f36246ab726ba6d570 --- moodle/mod/lamslesson/lang/en/lamslesson.php (.../lamslesson.php) (revision 606bc0215a34c4af3f93611e71553d8020d47036) +++ moodle/mod/lamslesson/lang/en/lamslesson.php (.../lamslesson.php) (revision fff4221d477dd2d8bbac61f36246ab726ba6d570) @@ -66,14 +66,16 @@ $string['requestsourceinfo'] = 'What is the name of your Moodle instance?. This value will appear after saving a sequence and will be used to prompt the user to "return to ". So here you can put the name you give your Moodle server. ie: "Virtual Campus"'; $string['validationbutton'] = "Validate settings"; -$string['validationinfo'] = 'Press the button to validate your settings.'; +$string['validationheader'] = 'Settings validation'; +$string['validationinfo'] = 'Before you save your settings, please press the button to validate them with the LAMS server. If the validation is correct, save these settings. If not, please check that the settings you have entered match with the values in the LAMS server'; +$string['validationhelp'] = 'Need help? check out the'; +$string['lamsmoodlehelp'] = 'LAMS-Moodle integration tutorial'; - +$string['validationsuccessful'] = 'Validation successful! You can now save your settings and start using LAMS within Moodle.'; +$string['validationfailed'] = 'Validation failed: please check that the settings you have entered match with the settings in LAMS'; // -$string['notsetup'] = 'Configuration is not complete'; - // Labels for errors when calling LAMS Server $string['restcall503'] = 'Call to LAMS failed: received an HTTP status of 503. This might mean that LAMS is unavailable. Please wait a minute and try again, or contact your system administrator.'; $string['restcall403'] = 'Call to LAMS failed: received an HTTP status of 403 Forbidden. Please check the configurations settings and/or contact your system administrator.'; Index: moodle/mod/lamslesson/lib.php =================================================================== diff -u -r458edcd7121d8676f627e7f74a06952a54423bf6 -rfff4221d477dd2d8bbac61f36246ab726ba6d570 --- moodle/mod/lamslesson/lib.php (.../lib.php) (revision 458edcd7121d8676f627e7f74a06952a54423bf6) +++ moodle/mod/lamslesson/lib.php (.../lib.php) (revision fff4221d477dd2d8bbac61f36246ab726ba6d570) @@ -54,6 +54,7 @@ define('LAMSLESSON_PARAM_MONITOR_METHOD', 'monitor'); define('LAMSLESSON_PARAM_LEARNER_METHOD', 'learner'); define('LAMSLESSON_PARAM_PREVIEW_METHOD', 'preview'); +define('LAMSLESSON_PARAM_VERIFY_METHOD', 'verify'); define('LAMSLESSON_PARAM_SINGLE_PROGRESS_METHOD', 'singleStudentProgress'); define('LAMSLESSON_PARAM_PROGRESS_METHOD', 'studentProgress'); define('LAMSLESSON_PARAM_CUSTOM_CSV', 'customCSV'); @@ -890,5 +891,36 @@ } else { lamslesson_grade_item_update($lamslesson); } + } +/** + * Verify Moodle settings with LAMS + * + * @param url $url + * @param string $id + * @param string $key + */ +function lamslesson_verify($url, $id, $key){ + + $datetime = date("F d,Y g:i a"); + $datetime_encoded = urlencode($datetime); + + $plaintext = $datetime.$id.$key; + // create hash + $hashvalue = sha1(strtolower($plaintext)); + + $request = $url . LAMSLESSON_LESSON_MANAGER . "?method=" . LAMSLESSON_PARAM_VERIFY_METHOD . "&serverId=" . $id . "&datetime=" . $datetime_encoded . "&hashValue=" . $hashvalue; + + $validate = file_get_contents($request); + + if ( $validate == 1 ) { + // validation successful + return get_string('validationsuccessful', 'lamslesson'); + } else { + // validation failed + return get_string('validationfailed', 'lamslesson'); + } + +} + Index: moodle/mod/lamslesson/styles.css =================================================================== diff -u -r606bc0215a34c4af3f93611e71553d8020d47036 -rfff4221d477dd2d8bbac61f36246ab726ba6d570 --- moodle/mod/lamslesson/styles.css (.../styles.css) (revision 606bc0215a34c4af3f93611e71553d8020d47036) +++ moodle/mod/lamslesson/styles.css (.../styles.css) (revision fff4221d477dd2d8bbac61f36246ab726ba6d570) @@ -11,6 +11,7 @@ #learnerbutton a {text-decoration:none;padding-left: 2.25em;background: url([[pix:t/go]]) 8% 50% no-repeat;} #monitorbutton a {text-decoration:none;padding-left: 2.25em;background: url([[pix:a/search]]) 5% 50% no-repeat;} #previewbutton a {text-decoration:none;padding-left: 2.25em;background: url([[pix:a/search]]) 5% 50% no-repeat;} +#validatebutton a {text-decoration:none;padding-left: 2.25em;background: url([[pix:i/admin]]) 5% 50% no-repeat;} /* Copyright (c) 2006 Yahoo! Inc. All rights reserved. This file is from: Index: moodle/mod/lamslesson/validate.js =================================================================== diff -u --- moodle/mod/lamslesson/validate.js (revision 0) +++ moodle/mod/lamslesson/validate.js (revision fff4221d477dd2d8bbac61f36246ab726ba6d570) @@ -0,0 +1,104 @@ + /* + * LAMSLesson validation + * + * Date: 2012-01-07 + * LAMS Foundation (http://lamsfoundation.org) + */ + + + var req; + var validated = -1; + var timer = null; + + function trim(str){ return str.replace(/^\s+|\s+$/, ''); } + + function resetValidated(){ validated = -1; } + + function validate(){ + var errstr = ""; + var num = -1; + var fields = new Array(3); + fields[0] = "id_s__lamslesson_serverurl"; + fields[1] = "id_s__lamslesson_serverid"; + fields[2] = "id_s__lamslesson_serverkey"; + + if(trim(document.getElementById("id_s__lamslesson_serverurl").value).length == 0){ + errstr += "* server_url " + document.getElementById("notempty").value ; + num = 0; + }else if (trim(document.getElementById("id_s__lamslesson_serverurl").value).search(/http:\/\//i) == -1){ + errstr += "* server_url " + document.getElementById("notvalid").value; + num = 0; + } + if(trim(document.getElementById("id_s__lamslesson_serverid").value).length == 0){ + errstr += "\n* server_id " + document.getElementById("notempty").value; + if(num == -1){ + num = 1; + } + } + + if(trim(document.getElementById("id_s__lamslesson_serverkey").value).length == 0){ + errstr += "\n* server_key " + document.getElementById("notempty").value; + if(num == -1){ + num = 2;; + } + } + + if(errstr.length > 0){ + alert(errstr); + document.getElementById(fields[num]).focus(); + validated = 0; + }else{ + verify(); + } + } + + function createQuery(){ + var pairs = new Array(); + pairs.push("u="+encodeURIComponent(document.getElementById("id_s__lamslesson_serverurl").value)); + pairs.push("i="+encodeURIComponent(document.getElementById("id_s__lamslesson_serverid").value)); + pairs.push("k="+encodeURIComponent(document.getElementById("id_s__lamslesson_serverkey").value)); + return pairs.join("&"); + } + + function verify(){ + timer = setTimeout('timeCount()', 5000); + var url = '../mod/lamslesson/verify.php'; + var contentType = "application/x-www-form-urlencoded; charset=UTF-8"; + var query = createQuery(); + if (window.XMLHttpRequest) { // Non-IE browsers + req = new XMLHttpRequest(); + req.onreadystatechange = getResult; + try { + req.open("POST", url, true); + req.setRequestHeader("Content-Type", contentType); + req.send(query); + } catch (e) { + clearTimeout(timer); + alert(e); + } + } else if (window.ActiveXObject) { // IE + req = new ActiveXObject("Microsoft.XMLHTTP"); + if (req) { + req.onreadystatechange = getResult; + req.open("POST", url, true); + req.setRequestHeader("Content-Type", contentType); + req.send(query); + }else{ + clearTimeout(timer); + } + } + } + function getResult(){ + if(req.readyState == 4){ //completed + if (req.responseText != '1'){ + alert(req.responseText); + } + clearTimeout(timer); + } + } + + function timeCount(){ + var originalTxt = document.getElementById("validatebtn").value; + document.getElementById("validatebtn").value = originalTxt + "..."; + } + Index: moodle/mod/lamslesson/verify.php =================================================================== diff -u --- moodle/mod/lamslesson/verify.php (revision 0) +++ moodle/mod/lamslesson/verify.php (revision fff4221d477dd2d8bbac61f36246ab726ba6d570) @@ -0,0 +1,9 @@ +dirroot.'/mod/lamslesson/lib.php'); +$u = required_param('u', PARAM_URL); +$i = required_param('i', PARAM_ALPHANUM); +$k = required_param('k', PARAM_ALPHANUM); + +echo lamslesson_verify($u, $i, $k); +?>