178 lines
5.3 KiB
PHP
178 lines
5.3 KiB
PHP
<?php
|
|
|
|
/*
|
|
|
|
SCORM 1.2 RTE
|
|
Rev 2009-11-30-01
|
|
Copyright (C) 2009, Addison Robson LLC
|
|
|
|
*/
|
|
|
|
// ------------------------------------------------------------------------------------
|
|
// Database-specific code
|
|
// ------------------------------------------------------------------------------------
|
|
function readElement($VarName) {
|
|
|
|
global $link;
|
|
global $SCOInstanceID;
|
|
$numerodeempleado = getFromLMS('cmi.core.student_id');
|
|
//$safeVarName = mysqli_escape_string($link,$VarName);
|
|
$safeVarName = $VarName;
|
|
$sql = "select VarValue from scormvars where ((SCOInstanceID=$SCOInstanceID) and (VarName='$safeVarName') && (numempl='$numerodeempleado'))";
|
|
$result = mysqli_query($link, $sql);
|
|
list($value) = mysqli_fetch_row($result);
|
|
|
|
return $value;
|
|
|
|
}
|
|
|
|
function writeElement($VarName,$VarValue) {
|
|
|
|
global $link;
|
|
global $SCOInstanceID;
|
|
$numerodeempleado = getFromLMS('cmi.core.student_id');
|
|
//$safeVarName = mysqli_escape_string($link,$VarName);
|
|
//$safeVarValue = mysqli_escape_string($link,$VarValue);
|
|
|
|
$safeVarName = $VarName;
|
|
$safeVarValue = $VarValue;
|
|
|
|
$sql ="update scormvars set VarValue='$safeVarValue' where ((SCOInstanceID=$SCOInstanceID) and (VarName='$safeVarName') && (numempl='$numerodeempleado'))";
|
|
mysqli_query($link, $sql);
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
function initializeElement($VarName,$VarValue) {
|
|
|
|
global $link;
|
|
global $SCOInstanceID;
|
|
|
|
// make safe for the database
|
|
//$safeVarName = mysqli_escape_string($link,$VarName);
|
|
//$safeVarValue = mysqli_escape_string($link,$VarValue);
|
|
|
|
$safeVarName = $VarName;
|
|
$safeVarValue = $VarValue;
|
|
|
|
|
|
$numerodeempleado = getFromLMS('cmi.core.student_id');
|
|
$sql ="select VarValue from scormvars where ( (numempl='$numerodeempleado') && (SCOInstanceID=$SCOInstanceID) and (VarName='$safeVarName'))";
|
|
// look for pre-existing values
|
|
$result = mysqli_query($link, $sql);
|
|
// if nothing found ...
|
|
if (!mysqli_num_rows($result)) {
|
|
$sql ="insert into scormvars (SCOInstanceID,VarName,VarValue,numempl) values ($SCOInstanceID,'$safeVarName','$safeVarValue','$numerodeempleado')";
|
|
mysqli_query($link, $sql);
|
|
}
|
|
|
|
}
|
|
|
|
function initializeSCO() {
|
|
|
|
global $link;
|
|
global $SCOInstanceID;
|
|
$numerodeempleado = getFromLMS('cmi.core.student_id');
|
|
// has the SCO previously been initialized?
|
|
//$sql = "SELECT Count(scormvars.varName) FROM `user` INNER JOIN scormvars ON `user`.numempl = scormvars.numempl WHERE
|
|
//scormvars.SCOInstanceID = $SCOInstanceID AND `user`.numempl = '$numerodeempleado'";
|
|
$sql ="select count(VarName) from scormvars where (SCOInstanceID=$SCOInstanceID) AND scormvars.numempl = '$numerodeempleado' ";
|
|
|
|
$result = mysqli_query($link, $sql);
|
|
list($count) = mysqli_fetch_row($result);
|
|
|
|
// not yet initialized - initialize all elements
|
|
if (! $count) {
|
|
// elements that tell the SCO which other elements are supported by this API
|
|
initializeElement('cmi.core._children','student_id,student_name,lesson_location,credit,lesson_status,entry,score,total_time,exit,session_time');
|
|
initializeElement('cmi.core.score._children','raw');
|
|
|
|
// student information
|
|
initializeElement('cmi.core.student_name',getFromLMS('cmi.core.student_name'));
|
|
initializeElement('cmi.core.student_id',getFromLMS('cmi.core.student_id'));
|
|
|
|
|
|
// test score
|
|
initializeElement('cmi.core.score.raw',''); // default 0
|
|
initializeElement('adlcp:masteryscore',getFromLMS('adlcp:masteryscore'));
|
|
|
|
// SCO launch and suspend data
|
|
initializeElement('cmi.launch_data',getFromLMS('cmi.launch_data'));
|
|
initializeElement('cmi.suspend_data','');
|
|
|
|
// progress and completion tracking
|
|
initializeElement('cmi.core.lesson_location','');
|
|
initializeElement('cmi.core.credit','credit');
|
|
initializeElement('cmi.core.lesson_status','not attempted');
|
|
initializeElement('cmi.core.entry','ab-initio');
|
|
initializeElement('cmi.core.exit','');
|
|
|
|
// seat time
|
|
initializeElement('cmi.core.total_time','0000:00:00');
|
|
initializeElement('cmi.core.session_time','');
|
|
|
|
}
|
|
|
|
// new session so clear pre-existing session time
|
|
writeElement('cmi.core.session_time','');
|
|
|
|
// create the javascript code that will be used to set up the javascript cache,
|
|
$initializeCache = "var cache = new Object();\n";
|
|
$sql ="select VarName,VarValue from scormvars where (SCOInstanceID=$SCOInstanceID && (numempl='$numerodeempleado'))";
|
|
$result = mysqli_query($link, $sql);
|
|
while (list($varname,$varvalue) = mysqli_fetch_row($result)) {
|
|
|
|
// make the value safe by escaping quotes and special characters
|
|
$jvarvalue = addslashes($varvalue);
|
|
|
|
// javascript to set the initial cache value
|
|
$initializeCache .= "cache['$varname'] = '$jvarvalue';\n";
|
|
|
|
}
|
|
|
|
// return javascript for cache initialization to the calling program
|
|
return $initializeCache;
|
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------
|
|
// LMS-specific code
|
|
// ------------------------------------------------------------------------------------
|
|
function setInLMS($varname,$varvalue) {
|
|
return "OK";
|
|
}
|
|
|
|
function getFromLMS($varname) {
|
|
|
|
switch ($varname) {
|
|
|
|
case 'cmi.core.student_name':
|
|
$user = json_decode($_SESSION['usersession']);
|
|
$varvalue = $user->nombre;
|
|
break;
|
|
|
|
case 'cmi.core.student_id':
|
|
$user = json_decode($_SESSION['usersession']);
|
|
$varvalue = $user->numempl;
|
|
break;
|
|
|
|
case 'adlcp:masteryscore':
|
|
$varvalue = 0;
|
|
break;
|
|
|
|
case 'cmi.launch_data':
|
|
$varvalue = "";
|
|
break;
|
|
|
|
default:
|
|
$varvalue = '';
|
|
|
|
}
|
|
|
|
return $varvalue;
|
|
|
|
}
|
|
|
|
?>
|