chore: version inicial del codigo fuente del LMS Estafeta

This commit is contained in:
2026-10-02 20:33:12 -06:00
commit c8bb6b97b9
1572 changed files with 457520 additions and 0 deletions
+390
View File
@@ -0,0 +1,390 @@
<?php
/*
VS SCORM 1.2 RTE - api.php
Rev 2010-04-30-01
Copyright (C) 2009, Addison Robson LLC
This program 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 2
of the License, or (at your option) any later version.
This program 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 this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
// read database login information and connect
//require_once "../config.php";
//session_name($CFG->sessionname);
//session_start();
// essential functions
require_once "subs.php";
require_once('mencrypt.php');
// input data
$SCOInstanceID = urldecode($_GET['SCOInstanceID']);
$SCOInstanceID = str_replace (' ','+', $SCOInstanceID );
$SCOInstanceID = $desencriptar( $SCOInstanceID );
$urlencrypt = urldecode($_GET['url']);
$urlencrypt = str_replace (' ','+', $urlencrypt );
$scourl = $desencriptar( $urlencrypt );
dbConnect();
// initialize data elements in the database if they're not already set, and
// dynamically create the javascript code to initialize the local cache
$initializeCache = initializeSCO();
?>
<script language="javascript">
var API = new Object();
// ------------------------------------------
// Status Flags
// ------------------------------------------
var flagFinished = false;
var flagInitialized = false;
// ------------------------------------------
// SCO Data Cache - Initialization
// ------------------------------------------
<?php print $initializeCache; ?>
// ------------------------------------------
// SCORM RTE Functions - Initialization
// ------------------------------------------
function LMSInitialize(dummyString) {
// already initialized or already finished
if ((flagInitialized) || (flagFinished)) { return "false"; }
// set initialization flag
flagInitialized = true;
if(cache['cmi.core.lesson_status'] = 'completed') {
flagFinished = true;
}
if(cache['cmi.core.score.raw'] = '100') {
flagFinished = true;
}
// return success value
return "true";
}
// ------------------------------------------
// SCORM RTE Functions - Getting and Setting Values
// ------------------------------------------
function LMSGetValue(varname) {
// not initialized or already finished
if ((!flagInitialized) ) { return "false"; }
// otherwise, return the requested data
return cache[varname];
}
function LMSSetValue(varname, varvalue) {
// not initialized or already finished
if ((!flagInitialized) ) { return "false"; }
// otherwise, set the requested data, and return success value
cache[varname] = varvalue;
//LMSCommit('');
return "true";
}
// ------------------------------------------
// SCORM RTE Functions - Saving the Cache to the Database
// ------------------------------------------
function LMSCommit(dummyString) {
// not initialized or already finished
if ((!flagInitialized) || (flagFinished)) { return "false"; }
// code to prevent caching
var d = new Date();
var data = new Object();
data['cmi.core.lesson_location'] = cache['cmi.core.lesson_location'];
data['cmi.core.lesson_status'] = cache['cmi.core.lesson_status'];
data['cmi.core.exit'] = cache['cmi.core.exit'];
data['cmi.core.score.raw'] = cache['cmi.core.score.raw'];
data['cmi.suspend_data'] = cache['cmi.suspend_data'];
data['cmi.core.session_time'] = cache['cmi.core.session_time'];
var elr = "";
$.ajax({
url: 'commit.php',
type: 'POST',
data: {
SCOInstanceID: <?php print $SCOInstanceID; ?>,
data: JSON.stringify(data),
code: d.getTime()
}
})
.done(function() {
elr = "true";
})
.fail(function() {
console.log('Problem with AJAX Request in LMSCommit()');
elr = "false";
})
.always(function() {
return elr;
});
}
// ------------------------------------------
// SCORM RTE Functions - Closing The Session
// ------------------------------------------
function LMSFinish(dummyString) {
// not initialized or already finished
if ((!flagInitialized) || (flagFinished)) { return "false"; }
var d = new Date();
// commit cached values to the database
//LMSCommit('');
var data = new Object();
data['cmi.core.lesson_location'] = cache['cmi.core.lesson_location'];
data['cmi.core.lesson_status'] = cache['cmi.core.lesson_status'];
data['cmi.core.exit'] = cache['cmi.core.exit'];
data['cmi.core.score.raw'] = cache['cmi.core.score.raw'];
data['cmi.suspend_data'] = cache['cmi.suspend_data'];
data['cmi.core.session_time'] = cache['cmi.core.session_time'];
// commit cached values to the database
// code to prevent caching
var computeTimeString = computeTime();
var elr = "";
$.ajax({
url: 'finish.php',
type: 'POST',
data: {
SCOInstanceID: <?php print $SCOInstanceID; ?>,
code: d.getTime(),
computeTimeString: computeTimeString,
data: JSON.stringify(data)
},
})
.done(function() {
elr = "true";
})
.fail(function() {
alert('Problem with AJAX Request in LMSFinish()');
elr = "";
})
.always(function() {
flagFinished = true;
return elr;
});
}
// ------------------------------------------
// SCORM RTE Functions - Error Handling
// ------------------------------------------
function LMSGetLastError() {
return 0;
}
function LMSGetDiagnostic(errorCode) {
return "diagnostic string";
}
function LMSGetErrorString(errorCode) {
return "error string";
}
// ------------------------------------------
// AJAX Request Handling
// ------------------------------------------
function createRequest() {
var request;
try {
request = new XMLHttpRequest();
} catch (tryIE) {
try {
request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (tryOlderIE) {
try {
request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (failed) {
alert("Error creating XMLHttpRequest");
}
}
}
return request;
}
// ------------------------------------------
// URL Encoding
// ------------------------------------------
function urlencode(str) {
var histogram = {},
unicodeStr = '',
hexEscStr = '';
var ret = (str + '').toString();
var replacer = function(search, replace, str) {
var tmp_arr = [];
tmp_arr = str.split(search);
return tmp_arr.join(replace);
};
// The histogram is identical to the one in urldecode.
histogram["'"] = '%27';
histogram['('] = '%28';
histogram[')'] = '%29';
histogram['*'] = '%2A';
histogram['~'] = '%7E';
histogram['!'] = '%21';
histogram['%20'] = '+';
histogram['\u00DC'] = '%DC';
histogram['\u00FC'] = '%FC';
histogram['\u00C4'] = '%D4';
histogram['\u00E4'] = '%E4';
histogram['\u00D6'] = '%D6';
histogram['\u00F6'] = '%F6';
histogram['\u00DF'] = '%DF';
histogram['\u20AC'] = '%80';
histogram['\u0081'] = '%81';
histogram['\u201A'] = '%82';
histogram['\u0192'] = '%83';
histogram['\u201E'] = '%84';
histogram['\u2026'] = '%85';
histogram['\u2020'] = '%86';
histogram['\u2021'] = '%87';
histogram['\u02C6'] = '%88';
histogram['\u2030'] = '%89';
histogram['\u0160'] = '%8A';
histogram['\u2039'] = '%8B';
histogram['\u0152'] = '%8C';
histogram['\u008D'] = '%8D';
histogram['\u017D'] = '%8E';
histogram['\u008F'] = '%8F';
histogram['\u0090'] = '%90';
histogram['\u2018'] = '%91';
histogram['\u2019'] = '%92';
histogram['\u201C'] = '%93';
histogram['\u201D'] = '%94';
histogram['\u2022'] = '%95';
histogram['\u2013'] = '%96';
histogram['\u2014'] = '%97';
histogram['\u02DC'] = '%98';
histogram['\u2122'] = '%99';
histogram['\u0161'] = '%9A';
histogram['\u203A'] = '%9B';
histogram['\u0153'] = '%9C';
histogram['\u009D'] = '%9D';
histogram['\u017E'] = '%9E';
histogram['\u0178'] = '%9F';
// Begin with encodeURIComponent, which most resembles PHP's encoding functions
ret = encodeURIComponent(ret);
for (unicodeStr in histogram) {
hexEscStr = histogram[unicodeStr];
ret = replacer(unicodeStr, hexEscStr, ret); // Custom replace. No regexing
}
// Uppercase for full PHP compatibility
return ret.replace(/(\%([a-z0-9]{2}))/g, function(full, m1, m2) {
return "%" + m2.toUpperCase();
});
}
API.LMSInitialize = LMSInitialize;
API.LMSGetValue = LMSGetValue;
API.LMSSetValue = LMSSetValue;
API.LMSCommit = LMSCommit;
API.LMSFinish = LMSFinish;
API.LMSGetLastError = LMSGetLastError;
API.LMSGetErrorString = LMSGetErrorString;
var startDate = 0;
function resizeIframe(iframe) {
var padding = 50;
if( $("#navsco").length > 0 ){
var navbar360 = $("#navsco").outerHeight();
}else{
var navbar360 = 0;
}
padding = padding + navbar360;
if (iframe.contentWindow.document.body.scrollHeight < (window.innerHeight - padding))
iframe.height = iframe.contentWindow.document.body.scrollHeight + "px";
else
iframe.height = (window.innerHeight + padding) + "px";
}
/**
* Descripción: Inica el conteo del tiempo en el sco
* @return
* @method startTimer
* @return
*/
function startTimer() {
startDate = new Date().getTime();
}
/**
* Descripción: calucla el tiempo que el usuario permance en el sco
* @method computeTime
* @return formattedTime
*/
function computeTime() {
var formattedTime = "00:00:00.0";
if (startDate != 0) {
var currentDate = new Date().getTime();
var elapsedSeconds = ((currentDate - startDate) / 1000);
formattedTime = convertTotalSeconds(elapsedSeconds);
}
return formattedTime;
}
/**
* Descripción: convierte el tiempo en segundos
* @method convertTotalSeconds
* @param ts de tipo time
* @return rtnVal
*/
function convertTotalSeconds(ts) {
var Sec = (ts % 60);
ts -= Sec;
var tmp = (ts % 3600);
ts -= tmp;
if ((ts % 3600) != 0) var Hour = "00";
else var Hour = "" + (ts / 3600);
if ((tmp % 60) != 0) var Min = "00";
else var Min = "" + (tmp / 60);
Sec = "" + Sec
Sec = Sec.substring(0, Sec.indexOf("."))
if (Hour.length < 2) Hour = "0" + Hour;
if (Min.length < 2) Min = "0" + Min;
if (Sec.length < 2) Sec = "0" + Sec;
var rtnVal = Hour + ":" + Min + ":" + Sec;
return rtnVal;
}
</script>
<?php
function generateRandomString($length = 10) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
return $randomString;
}
echo '<iframe onload="resizeIframe(this)"
onresize="resizeIframe(this)" frameborder="0" allowfullscreen src="'.$scourl.'?nocache='.generateRandomString(). '"
class="w-100 h-100 position-absolute scormiframe" id="scormiframe360" style="top:0; left:0">
</iframe>';
echo '
<script type="text/javascript">
startTimer();
window.onresize = function() {
//resizeIframe(document.getElementById("scormiframe360"));
}
</script>';
?>
+53
View File
@@ -0,0 +1,53 @@
<?php
/*
VS SCORM 1.2 RTE - commit.php
Rev 2009-11-30-01
Copyright (C) 2009, Addison Robson LLC
This program 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 2
of the License, or (at your option) any later version.
This program 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 this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
// read database login information and connect
require_once "../config.php";
session_name($CFG->sessionname);
session_start();
// essential functions
require_once "subs.php";
dbConnect();
// read SCOInstanceID
$SCOInstanceID = $_POST['SCOInstanceID'];
$data = json_decode ($_POST['data'],true);
if (! is_array($data)) { $data = array($data); }
// iterate through the data elements
foreach ($data as $varname => $varvalue) {
// save data to the 'scormvars' table
writeElement($varname,$varvalue);
// special cases - set appropriate values in the LMS tables when they are set by the course
if ($varname == "cmi.core.score.raw") { setInLMS('TestScore',$varvalue); }
if ($varname == "cmi.core.lesson_status") { setInLMS('Finished',$varvalue); }
}
mysqli_close($link);
// return value to the calling program
print "true";
?>
+26
View File
@@ -0,0 +1,26 @@
<?php
function encrypt_decrypt($action, $string) {
$output = false;
$encrypt_method = "AES-256-CBC";
$secret_key = 'C0YwBhAR$f8vhHoBE1XZC5*bQvNa0XZ%GeZUVCTG*1F8h^RKwv';
$secret_iv = 'aes-256-cbc';
// hash
$key = hash('sha256', $secret_key);
// iv - encrypt method AES-256-CBC expects 16 bytes - else you will get a warning
+143
View File
@@ -0,0 +1,143 @@
<?php
/*
VS SCORM 1.2 RTE - finish.php
Rev 2010-04-30-01
Copyright (C) 2009, Addison Robson LLC
This program 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 2
of the License, or (at your option) any later version.
This program 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 this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
// read database login information and connect
require_once "../config.php";
session_name($CFG->sessionname);
session_start();
// essential functions
require_once "subs.php";
dbConnect();
// read form variables
$SCOInstanceID = $_POST['SCOInstanceID'];
$computeTime = $_POST['computeTime'];
//$SCOInstanceID = str_replace (' ','+', $SCOInstanceID );
//$SCOInstanceID = $desencriptar( $SCOInstanceID );
$data = json_decode ($_POST['data'],true);
if (! is_array($data)) { $data = array($data); }
// iterate through the data elements
foreach ($data as $varname => $varvalue) {
// save data to the 'scormvars' table
writeElement($varname,$varvalue);
// special cases - set appropriate values in the LMS tables when they are set by the course
if ($varname == "cmi.core.score.raw") { setInLMS('TestScore',$varvalue); }
if ($varname == "cmi.core.lesson_status") { setInLMS('Finished',$varvalue); }
}
// ------------------------------------------------------------------------------------
// set cmi.core.lesson_status
// find existing value of cmi.core.lesson_status
$lessonstatus = readElement('cmi.core.lesson_status');
// if it's 'not attempted', change it to 'completed'
if ($lessonstatus == 'not attempted') {
writeElement('cmi.core.lesson_status','completed');
}
// has a mastery score been specified in the IMS manifest file?
$masteryscore = readElement('adlcp:masteryscore');
$masteryscore *= 1;
if ($masteryscore) {
// yes - so read the score
$rawscore = readElement('cmi.core.score.raw');
$rawscore *= 1;
// set cmi.core.lesson_status to passed/failed
if ($rawscore >= $masteryscore) {
writeElement('cmi.core.lesson_status','passed');
}
else {
writeElement('cmi.core.lesson_status','failed');
}
}
// ------------------------------------------------------------------------------------
// set cmi.core.entry based on the value of cmi.core.exit
// clear existing value
writeElement('cmi.core.entry','');
// new entry value depends on exit value
$exit = readElement('cmi.core.exit');
if ($exit == 'suspend') {
writeElement('cmi.core.entry','resume');
}
else {
writeElement('cmi.core.entry','');
}
// ------------------------------------------------------------------------------------
// process changes to cmi.core.total_time
// read cmi.core.total_time from the 'scormvars' table
$totaltime = readElement('cmi.core.total_time');
// convert total time to seconds
$time = explode(':',$totaltime);
$totalseconds = $time[0]*60*60 + $time[1]*60 + $time[2];
// read the last-set cmi.core.session_time from the 'scormvars' table
$sessiontime = readElement('cmi.core.session_time');
// no session time set by SCO - set to zero
if (!$sessiontime) {
$sessiontime = $computeTime; // siempre se detecta el tiempo
}
// convert session time to seconds
$time = explode(':',$sessiontime);
$sessionseconds = $time[0]*60*60 + $time[1]*60 + $time[2];
// new total time is ...
$totalseconds += $sessionseconds;
// break total time into hours, minutes and seconds
$totalhours = intval($totalseconds / 3600);
$totalseconds -= $totalhours * 3600;
$totalminutes = intval($totalseconds / 60);
$totalseconds -= $totalminutes * 60;
// reformat to comply with the SCORM data model
$totaltime = sprintf("%04d:%02d:%02d",$totalhours,$totalminutes,$totalseconds);
// save new total time to the 'scormvars' table
writeElement('cmi.core.total_time',$totaltime);
// delete the last session time
writeElement('cmi.core.session_time','');
// ------------------------------------------------------------------------------------
mysqli_close($link);
// return value to the calling program
print "true";
?>
+94
View File
@@ -0,0 +1,94 @@
<?php
// Endpoint JSON: nunca emitir HTML de avisos/errores.
@ini_set('display_errors', '0');
@ini_set('display_startup_errors', '0');
error_reporting(E_ALL & ~E_DEPRECATED & ~E_NOTICE);
if (ob_get_level() === 0) { @ob_start(); }
require_once("../config.php");
if (session_status() === PHP_SESSION_NONE) {
session_name($CFG->sessionname);
session_start();
}
while (ob_get_level() > 0) { @ob_end_clean(); }
header('Content-Type: application/json; charset=utf-8');
if (empty($_SESSION['usersession'])) {
http_response_code(401);
echo json_encode(array('code' => '0', 'msg' => 'Sesión no válida'), JSON_UNESCAPED_UNICODE);
exit;
}
$user = json_decode($_SESSION['usersession']);
if (!$user || empty($user->userid)) {
echo json_encode(array('code' => '0', 'msg' => 'Sesión no válida'), JSON_UNESCAPED_UNICODE);
exit;
}
$sql = "SELECT
asignacion.id,
asignacion.uid,
asignacion.catid,
categoria.clave,
categoria.nombre,
categoria.imagen,
categoria.descripcion
FROM
asignacion
INNER JOIN categoria ON asignacion.catid = categoria.id
WHERE
asignacion.uid = $user->userid
AND categoria.habilitado = 1
ORDER BY
categoria.order_desc asc
";
$return = new stdClass();
$return->user = $user;
global $link;
dbConnect();
$result = mysqli_query($link, $sql);
if ( mysqli_num_rows($result) <= 0 ) {
$return->code = "0";
$return->msg="Sin cursos asignados";
echo json_encode($return, JSON_UNESCAPED_UNICODE);
exit;
}
$return->code = "1";
$return->msg="Cursos asignados";
while ($row = mysqli_fetch_assoc ($result)){
+44
View File
@@ -0,0 +1,44 @@
<?php
require_once('../config.php');
require_once ('mencrypt.php');
dbConnect();
$recursoid = $_GET['recursoid'];
global $link;
// obtener el sco a lanzar del RTE
$sql ="select * from scormpkg where id=$recursoid";
$result = mysqli_query($link, $sql);
if( mysqli_num_rows($result) ){
$sco = mysqli_fetch_array($result);
} else {
echo "No se encuentra en curso solicitado.";
die;
}
mysqli_free_result($result);
mysqli_close($link);
$url_encriptado = $encriptar($sco['url']);
$id_encriptado = $encriptar($sco['id']);
$idcat_encriptado = $encriptar($sco['idcategoria']);
// RTE central: se carga en el mismo request (sin redirect, evita 404)
$rte_central = __DIR__.'/sco.php';
if (is_file($rte_central)) {
$_GET['SCOInstanceID'] = urlencode($id_encriptado);
$_GET['url'] = urlencode($url_encriptado);
$_GET['idcat'] = urlencode($idcat_encriptado);
require $rte_central;
exit;
}
// Respaldo: sco.php dentro de la carpeta del paquete
$scolink = str_replace("index.html", "sco.php", $sco['url']);
$vars = $scolink."?SCOInstanceID=".urlencode($id_encriptado)."&url=".urlencode($url_encriptado)."&idcat=".urlencode($idcat_encriptado);
header('Location: '.$vars);
exit;
?>
+41
View File
@@ -0,0 +1,41 @@
<?php
require_once ("../config.php");
try {
session_name($CFG->sessionname);
session_start();
unset($_SESSION['usersession']);
session_unset();
// Stores in Array
$_SESSION = array();
// Swipe via memory
if (ini_get("session.use_cookies")) {
// Prepare and swipe cookies
$params = session_get_cookie_params();
// clear cookies and sessions
setcookie(session_name(), '', time() - 42000,
$params["path"], $params["domain"],
$params["secure"], $params["httponly"]
);
}
// IF THE SESSION IS KEPT IN COOKIE, FORCE SESSION COOKIE TO EXPIRE
$cookie_expires = time() - 42000;
if (isset($_COOKIE[session_name()]))
{
setcookie(session_name(), '', $cookie_expires, '/');
}
// Just in case.. swipe these values too
ini_set('session.gc_max_lifetime', 0);
ini_set('session.gc_probability', 1);
ini_set('session.gc_divisor', 1);
// Completely destory our server sessions..
session_destroy();
session_write_close();
} catch (Exception $e) {
} finally {
header("Location:".$CFG->wwwroot);
}
?>
+36
View File
@@ -0,0 +1,36 @@
<?php
//Configuración del algoritmo de encriptación
//Debes cambiar esta cadena, debe ser larga y unica
//nadie mas debe conocerla
$clavecript = 'C0YwBhAR$f8vhHoBE1XZC5*bQvNa0XZ%GeZUVCTG*1F8h^RKwv';
//Metodo de encriptación
$method = 'aes-256-cbc';
// Puedes generar una diferente usando la funcion $getIV()
$iv = base64_decode("C9fBxl1EWtYTL1/M8jfstw==");
/*
Encripta el contenido de la variable, enviada como parametro.
*/
$encriptar = function ($valor) use ($method, $clavecript, $iv) {
return openssl_encrypt ($valor, $method, $clavecript, false, $iv);
};
/*
Desencripta el texto recibido
*/
$desencriptar = function ($valor) use ($method, $clavecript, $iv) {
$encrypted_data = base64_decode($valor);
return openssl_decrypt($valor, $method, $clavecript, false, $iv);
};
/*
Genera un valor para IV
*/
$getIV = function () use ($method) {
return base64_encode(openssl_random_pseudo_bytes(openssl_cipher_iv_length($method)));
};
?>
+98
View File
@@ -0,0 +1,98 @@
<?php
require_once('../config.php');
require_once ('mencrypt.php');
session_name($CFG->sessionname);
session_start();
global $link;
dbConnect();
// Check connection
if (!$link) {
die("Connection failed: " . mysqli_connect_error());
}
$numerodeempleado = isset($_POST['numempl']) ? trim($_POST['numempl']) : '';
// Límite de intentos por IP (mitiga enumeración / fuerza bruta)
function lms_rate_limit($key, $max = 60, $window = 600) {
$file = sys_get_temp_dir() . '/lms_rl_' . md5($key);
$now = time();
$data = array();
if (is_file($file)) {
$tmp = json_decode(@file_get_contents($file), true);
if (is_array($tmp)) { $data = $tmp; }
}
$data = array_values(array_filter($data, function ($t) use ($now, $window) {
return $t > $now - $window;
}));
if (count($data) >= $max) { return false; }
$data[] = $now;
@file_put_contents($file, json_encode($data), LOCK_EX);
return true;
}
$userip = getUserIP();
if (!lms_rate_limit('login_' . $userip)) {
header("Location:".$CFG->wwwroot.'?errorcode=0');
exit;
}
// Buscar usuario (consulta preparada)
$stmt = mysqli_prepare($link, "select * from user where numempl = ? and habilitado = 1 limit 1");
mysqli_stmt_bind_param($stmt, 's', $numerodeempleado);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
$user = $result ? mysqli_fetch_array($result) : null;
mysqli_stmt_close($stmt);
if (!$user) {
header("Location:".$CFG->wwwroot.'?errorcode=0');
exit;
}
// Actualizar último acceso (consulta preparada)
$stmt = mysqli_prepare($link, "update user set lastip = ?, lastlogin = NOW() where numempl = ?");
mysqli_stmt_bind_param($stmt, 'ss', $userip, $numerodeempleado);
mysqli_stmt_execute($stmt);
mysqli_stmt_close($stmt);
// Evitar fijación de sesión
session_regenerate_id(true);
$_SESSION['usersession'] = json_encode($user, JSON_UNESCAPED_UNICODE);
$_SESSION['numerodeempleado'] = $numerodeempleado;
$url_encriptado = $encriptar($numerodeempleado);
if ($user['idrol'] == 1) {
$_SESSION['isadmin'] = false;
$vars = "../dashboard.php?uniq=".urlencode($url_encriptado);
header('Location: '.$vars);
exit;
} else {
$_SESSION['isadmin'] = true;
header('Location: ../admin/');
exit;
}
function getUserIP() {
$ipaddress = '';
if (isset($_SERVER['HTTP_CLIENT_IP']))
$ipaddress = $_SERVER['HTTP_CLIENT_IP'];
else if(isset($_SERVER['HTTP_X_FORWARDED_FOR']))
$ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
else if(isset($_SERVER['HTTP_X_FORWARDED']))
$ipaddress = $_SERVER['HTTP_X_FORWARDED'];
else if(isset($_SERVER['HTTP_X_CLUSTER_CLIENT_IP']))
$ipaddress = $_SERVER['HTTP_X_CLUSTER_CLIENT_IP'];
else if(isset($_SERVER['HTTP_FORWARDED_FOR']))
$ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
else if(isset($_SERVER['HTTP_FORWARDED']))
$ipaddress = $_SERVER['HTTP_FORWARDED'];
else if(isset($_SERVER['REMOTE_ADDR']))
$ipaddress = $_SERVER['REMOTE_ADDR'];
else
$ipaddress = 'UNKNOWN';
return substr($ipaddress, 0, 100);
}
?>
+23
View File
@@ -0,0 +1,23 @@
<?php
require_once('../sessionManager.php');
header('Expires: Sun, 01 Jan 2014 00:00:00 GMT');
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
?>
<!DOCTYPE html>
<html>
<head>
<?php include "../header.php" ?>
<link rel="stylesheet" type="text/css" href="<?php echo $CFG->wwwroot ?>css/sco.css">
</head>
<body>
<script type="text/javascript" src="<?php echo $CFG->wwwroot ?>js/jquery-3.4.1.min.js"></script>
<?php include "api.php"; ?>
</body>
</html>
+417
View File
@@ -0,0 +1,417 @@
function LMSInitialize(dummyString) {
// already initialized or already finished
/*if ((flagInitialized) || (flagFinished)) {
if( flagFinished ){
return "false";
}else{
return "true";
}
}*/
// set initialization flag
flagInitialized = true;
/*
if (LMSGetValue('cmi.core.score.raw') == '100' &&
LMSGetValue('cmi.core.lesson_status') == 'completed'
|| LMSGetValue('cmi.core.lesson_status') == 'passed' ) {
*/
if ( LMSGetValue('cmi.core.lesson_status') == 'completed'
|| LMSGetValue('cmi.core.lesson_status') == 'passed' ) {
flagFinished = true;
window.removeEventListener("onunload", LMSFinish);
window.removeEventListener("onbeforeunload", LMSFinish);
$('.btn-return').show();
} else {
flagFinished = false;
$('.btn-return').hide();
}
//console.dir(cache);
// return success value
return "true";
}
// ------------------------------------------
// SCORM RTE Functions - Getting and Setting Values
// ------------------------------------------
function LMSGetValue(varname) {
// not initialized or already finished
if ((!flagInitialized)) {
return "false";
}
// otherwise, return the requested data
return cache[varname];
}
function LMSSetValue(varname, varvalue) {
// not initialized or already finished
if ((!flagInitialized)) {
return "false";
}
// otherwise, set the requested data, and return success value
cache[varname] = varvalue;
if( varname == "cmi.core.score.raw" || varname == "cmi.core.lesson_status"){
LMSRealCommit('');
}
return "true";
}
// ------------------------------------------
// SCORM RTE Functions - Saving the Cache to the Database
// ------------------------------------------
function LMSCommit(dummyString) {
return "true";
}
// ------------------------------------------
// SCORM RTE Functions - Saving the Cache to the Database
// ------------------------------------------
function LMSRealCommit(dummyString) {
// not initialized or already finished
if ((!flagInitialized) || (flagFinished)) {
return "false";
} else {
// code to prevent caching
var d = new Date();
var data = new Object();
data['cmi.core.lesson_location'] = cache['cmi.core.lesson_location'];
data['cmi.core.lesson_status'] = cache['cmi.core.lesson_status'];
data['cmi.core.exit'] = cache['cmi.core.exit'];
data['cmi.core.score.raw'] = cache['cmi.core.score.raw'];
if (cache['cmi.core.score.raw'] == "100") {
data['cmi.core.lesson_status'] = "completed";
}
if (cache['cmi.core.lesson_status'] == "completed" || cache['cmi.core.lesson_status'] == "passed") {
$('.btn-return').show();
}
data['cmi.suspend_data'] = cache['cmi.suspend_data'];
data['cmi.core.session_time'] = cache['cmi.core.session_time'];
var elr = "";
$.ajax({
url: basepathsaves__ + 'runtime/commit.php',
type: 'POST',
data: {
SCOInstanceID: SCOInstanceID,
data: JSON.stringify(data),
code: d.getTime()
}
})
.done(function() {
if (cache['cmi.core.score.raw'] == "100" && cache['cmi.core.lesson_status'] == "completed") {
flagFinished = true;
$('.btn-return').show();
}
elr = "true";
})
.fail(function() {
console.log('Problem with AJAX Request in LMSCommit()');
elr = "false";
})
.always(function() {
return elr;
});
}
}
// ------------------------------------------
// SCORM RTE Functions - Closing The Session
// ------------------------------------------
function LMSFinish(dummyString) {
var body = document.body,
html = document.documentElement;
var height = Math.max(body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight);
if( $(".layer-load").length > 0 ){
document.getElementsByClassName("layer-load")[0].style.height = height + "px";
document.getElementsByClassName("layer-load")[0].style.display = "block";
window.onresize = function(event) {
var body = document.body,
html = document.documentElement;
var height = Math.max(body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight);
document.getElementsByClassName("layer-load")[0].style.height = height + "px";
};
}
// not initialized or already finished
if ((!flagInitialized) || (flagFinished)) {
console.log("out");
} else {
flagFinished = true;
var d = new Date();
// commit cached values to the database
// not initialized or already finished
// code to prevent caching
var d = new Date();
var data = new Object();
data['cmi.core.lesson_location'] = cache['cmi.core.lesson_location'];
data['cmi.core.lesson_status'] = cache['cmi.core.lesson_status'];
data['cmi.core.exit'] = cache['cmi.core.exit'];
data['cmi.core.score.raw'] = cache['cmi.core.score.raw'];
if (cache['cmi.core.score.raw'] == "100") {
data['cmi.core.lesson_status'] = "completed";
}
if (cache['cmi.core.lesson_status'] == "completed" || cache['cmi.core.lesson_status'] == "passed") {
$('.btn-return').show();
}
data['cmi.suspend_data'] = cache['cmi.suspend_data'];
data['cmi.core.session_time'] = cache['cmi.core.session_time'];
var elr = "";
$.ajax({
url: basepathsaves__ + 'runtime/commit.php',
type: 'POST',
data: {
SCOInstanceID: SCOInstanceID,
data: JSON.stringify(data),
code: d.getTime()
}
})
.done(function() {
elr = "true";
})
.fail(function() {
console.log('Problem with AJAX Request in LMSCommit()');
elr = "false";
})
.always(function() {
return elr;
});
//var data = new Object();
//data['cmi.core.lesson_location'] = cache['cmi.core.lesson_location'];
//data['cmi.core.lesson_status'] = cache['cmi.core.lesson_status'];
//data['cmi.core.exit'] = cache['cmi.core.exit'];
//data['cmi.core.score.raw'] = cache['cmi.core.score.raw'];
//data['cmi.suspend_data'] = cache['cmi.suspend_data'];
//data['cmi.core.session_time'] = cache['cmi.core.session_time'];
// commit cached values to the database
// code to prevent caching
/*var computeTimeString = computeTime();
var elr = "";
$.ajax({
url: basepathsaves__+'runtime/finish.php',
type: 'POST',
data: {
SCOInstanceID: SCOInstanceID,
code: d.getTime(),
computeTimeString: computeTimeString,
data: JSON.stringify(data)
},
})
.done(function() {
elr = "true";
})
.fail(function() {
alert('Problem with AJAX Request in LMSFinish()');
elr = "";
})
.always(function() {
flagFinished = true;
return elr;
});*/
}
}
window.addEventListener("pagehide", LMSFinish);
window.onbeforeunload = LMSFinish;
// ------------------------------------------
// SCORM RTE Functions - Error Handling
// ------------------------------------------
function LMSGetLastError() {
return 0;
}
function LMSGetDiagnostic(errorCode) {
return "";
}
function LMSGetErrorString(errorCode) {
return "";
}
// ------------------------------------------
// AJAX Request Handling
// ------------------------------------------
function createRequest() {
var request;
try {
request = new XMLHttpRequest();
} catch (tryIE) {
try {
request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (tryOlderIE) {
try {
request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (failed) {
alert("Error creating XMLHttpRequest");
}
}
}
return request;
}
// ------------------------------------------
// URL Encoding
// ------------------------------------------
function urlencode(str) {
var histogram = {},
unicodeStr = '',
hexEscStr = '';
var ret = (str + '').toString();
var replacer = function(search, replace, str) {
var tmp_arr = [];
tmp_arr = str.split(search);
return tmp_arr.join(replace);
};
// The histogram is identical to the one in urldecode.
histogram["'"] = '%27';
histogram['('] = '%28';
histogram[')'] = '%29';
histogram['*'] = '%2A';
histogram['~'] = '%7E';
histogram['!'] = '%21';
histogram['%20'] = '+';
histogram['\u00DC'] = '%DC';
histogram['\u00FC'] = '%FC';
histogram['\u00C4'] = '%D4';
histogram['\u00E4'] = '%E4';
histogram['\u00D6'] = '%D6';
histogram['\u00F6'] = '%F6';
histogram['\u00DF'] = '%DF';
histogram['\u20AC'] = '%80';
histogram['\u0081'] = '%81';
histogram['\u201A'] = '%82';
histogram['\u0192'] = '%83';
histogram['\u201E'] = '%84';
histogram['\u2026'] = '%85';
histogram['\u2020'] = '%86';
histogram['\u2021'] = '%87';
histogram['\u02C6'] = '%88';
histogram['\u2030'] = '%89';
histogram['\u0160'] = '%8A';
histogram['\u2039'] = '%8B';
histogram['\u0152'] = '%8C';
histogram['\u008D'] = '%8D';
histogram['\u017D'] = '%8E';
histogram['\u008F'] = '%8F';
histogram['\u0090'] = '%90';
histogram['\u2018'] = '%91';
histogram['\u2019'] = '%92';
histogram['\u201C'] = '%93';
histogram['\u201D'] = '%94';
histogram['\u2022'] = '%95';
histogram['\u2013'] = '%96';
histogram['\u2014'] = '%97';
histogram['\u02DC'] = '%98';
histogram['\u2122'] = '%99';
histogram['\u0161'] = '%9A';
histogram['\u203A'] = '%9B';
histogram['\u0153'] = '%9C';
histogram['\u009D'] = '%9D';
histogram['\u017E'] = '%9E';
histogram['\u0178'] = '%9F';
// Begin with encodeURIComponent, which most resembles PHP's encoding functions
ret = encodeURIComponent(ret);
for (unicodeStr in histogram) {
hexEscStr = histogram[unicodeStr];
ret = replacer(unicodeStr, hexEscStr, ret); // Custom replace. No regexing
}
// Uppercase for full PHP compatibility
return ret.replace(/(\%([a-z0-9]{2}))/g, function(full, m1, m2) {
return "%" + m2.toUpperCase();
});
}
API.LMSInitialize = LMSInitialize;
API.LMSGetValue = LMSGetValue;
API.LMSSetValue = LMSSetValue;
API.LMSCommit = LMSCommit;
API.LMSFinish = LMSFinish;
API.LMSGetLastError = LMSGetLastError;
API.LMSGetErrorString = LMSGetErrorString;
API.LMSGetDiagnostic = LMSGetDiagnostic;
var startDate = 0;
function resizeIframe(iframe) {
var padding = 50;
if ($("#navsco").length > 0) {
var navbar360 = $("#navsco").outerHeight();
} else {
var navbar360 = 0;
}
padding = padding + navbar360;
if (iframe.contentWindow.document.body.scrollHeight < (window.innerHeight - padding))
iframe.height = iframe.contentWindow.document.body.scrollHeight + "px";
else
iframe.height = (window.innerHeight + padding) + "px";
}
/**
* Descripción: Inica el conteo del tiempo en el sco
* @return
* @method startTimer
* @return
*/
function startTimer() {
startDate = new Date().getTime();
}
/**
* Descripción: calucla el tiempo que el usuario permance en el sco
* @method computeTime
* @return formattedTime
*/
function computeTime() {
var formattedTime = "00:00:00.0";
if (startDate != 0) {
var currentDate = new Date().getTime();
var elapsedSeconds = ((currentDate - startDate) / 1000);
formattedTime = convertTotalSeconds(elapsedSeconds);
}
return formattedTime;
}
/**
* Descripción: convierte el tiempo en segundos
* @method convertTotalSeconds
* @param ts de tipo time
* @return rtnVal
*/
function convertTotalSeconds(ts) {
var Sec = (ts % 60);
ts -= Sec;
var tmp = (ts % 3600);
ts -= tmp;
if ((ts % 3600) != 0) var Hour = "00";
else var Hour = "" + (ts / 3600);
if ((tmp % 60) != 0) var Min = "00";
else var Min = "" + (tmp / 60);
Sec = "" + Sec
Sec = Sec.substring(0, Sec.indexOf("."))
if (Hour.length < 2) Hour = "0" + Hour;
if (Min.length < 2) Min = "0" + Min;
if (Sec.length < 2) Sec = "0" + Sec;
var rtnVal = Hour + ":" + Min + ":" + Sec;
return rtnVal;
}
+67
View File
@@ -0,0 +1,67 @@
<?php
ini_set('display_errors', 0);
ini_set('display_startup_errors', 0);
error_reporting(E_ALL & ~E_DEPRECATED & ~E_NOTICE);
require_once $_SERVER['DOCUMENT_ROOT']."/sessionManager.php";
require_once $_SERVER['DOCUMENT_ROOT']."/runtime/subs.php";
require_once($_SERVER['DOCUMENT_ROOT'].'/runtime/mencrypt.php');
$SCOInstanceID = urldecode($_GET['SCOInstanceID']);
$SCOInstanceID = str_replace(' ', '+', $SCOInstanceID);
$SCOInstanceID = $desencriptar($SCOInstanceID);
$urlencrypt = urldecode($_GET['url']);
$urlencrypt = str_replace(' ', '+', $urlencrypt);
$scourl = $desencriptar($urlencrypt);
$idcat = 0;
if (isset($_GET['idcat'])) {
$idcat_enc = urldecode($_GET['idcat']);
$idcat_enc = str_replace(' ', '+', $idcat_enc);
$idcat = $desencriptar($idcat_enc);
}
dbConnect();
$initializeCache = initializeSCO();
mysqli_close($link);
$returnUrl = $CFG->wwwroot.'recursos.php?idcat='.$idcat;
$iframeSrc = $scourl . (strpos($scourl, '?') === false ? '?' : '&') . 'v=' . time();
?>
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>SCO</title>
<script>
var API = new Object();
var flagFinished = false;
var flagInitialized = false;
var SCOInstanceID = <?php echo $SCOInstanceID; ?>;
var basepathsaves__ = "<?php echo $CFG->wwwroot; ?>";
<?php echo $initializeCache; ?>
</script>
<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
<script type="text/javascript" src="<?php echo $CFG->wwwroot; ?>runtime/runtime.js" charset="utf-8"></script>
<style>
html,body{margin:0;padding:0;height:100%;overflow:hidden;}
#sco-bar{position:fixed;top:0;left:0;width:100%;height:48px;background:#2b2b2b;z-index:9999;display:flex;align-items:center;padding:0 12px;box-sizing:border-box;}
#btn-regresar{background:#848484;color:#fff;padding:7px 14px;border:2px solid #848484;border-radius:4px;font-weight:800;cursor:pointer;}
#scormiframe{position:fixed;top:48px;left:0;width:100%;height:calc(100% - 48px);border:0;}
</style>
</head>
<body>
<div id="sco-bar">
<button id="btn-regresar">Regresar al menú anterior</button>
</div>
<iframe id="scormiframe" src="<?php echo htmlspecialchars($iframeSrc, ENT_QUOTES); ?>" allowfullscreen></iframe>
<script type="text/javascript">
$("#btn-regresar").click(function(){
if (typeof API !== "undefined") { if (API.LMSFinish) { API.LMSFinish(""); } }
setTimeout(function(){ window.location = "<?php echo $returnUrl; ?>"; }, 700);
});
</script>
</body>
</html>
+198
View File
@@ -0,0 +1,198 @@
<?php
ini_set("allow_url_include", "1");
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
/*
VS SCORM 1.2 RTE - api.php
Rev 2010-04-30-01
Copyright (C) 2009, Addison Robson LLC
This program 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 2
of the License, or (at your option) any later version.
This program 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 this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
// read database login information and connect
require_once $_SERVER['DOCUMENT_ROOT']."/git/estafeta-lms360/site/sessionManager.php";
// essential functions
require_once $_SERVER['DOCUMENT_ROOT']."/git/estafeta-lms360/site/runtime/subs.php";
require_once($_SERVER['DOCUMENT_ROOT'].'/git/estafeta-lms360/site/runtime/mencrypt.php');
// input data
$SCOInstanceID = urldecode($_GET['SCOInstanceID']);
$SCOInstanceID = str_replace (' ','+', $SCOInstanceID );
$SCOInstanceID = $desencriptar( $SCOInstanceID );
$urlencrypt = urldecode($_GET['url']);
$urlencrypt = str_replace (' ','+', $urlencrypt );
$scourl = $desencriptar( $urlencrypt );
dbConnect();
// initialize data elements in the database if they're not already set, and
// dynamically create the javascript code to initialize the local cache
$initializeCache = initializeSCO();
$apistring = "";
//$scoobj = file_get_contents($scourl);
//$porciones = explode("</script>", $scoobj);
//var_dump($porciones);
/*$doc = new DOMDocument();
$doc->loadHtml($scoobj);
$body = $doc->getElementsByTagName('body');
$body->append($apistring);
echo $doc->saveHTML();*/
$apistring = '<script>
var API = new Object();
var flagFinished = false;
var flagInitialized = false;
var SCOInstanceID = '.$SCOInstanceID.';
var basepathsaves__ = "'.$CFG->wwwroot.'";
'.$initializeCache.';</script>';
$apistring .= '<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>';
$apistring .= '<script type="text/javascript" src="'.$CFG->wwwroot.'runtime/runtime.js" charset="utf-8"></script>';
$apistring .= '<button class="btn-return" style="z-index: 50; position: absolute; background: #848484; color: #ffffff; padding: 7px; border: solid #848484 2px; border-radius: 4px; font-weight: 800; margin-left: 1%; margin-top: 1%; cursor:pointer;" >Regresar al menú anterior</button>';
$apistring .= '<script type="text/javascript">$(".btn-return").click(function(){ let prevUrl = document.referrer; window.location=prevUrl; });</script>';
$dom = new DOMDocument();
libxml_use_internal_errors(true);
$context = stream_context_create(array(
"ssl"=>array(
'verify_peer' => false,
'verify_peer_name' => false
)
));
function get_file_path_from_url( $file_url ){
return realpath($_SERVER['DOCUMENT_ROOT'] . parse_url( $file_url, PHP_URL_PATH ));
}
libxml_set_streams_context($context);
$dom->loadHTMLFile(get_file_path_from_url($scourl));
//get the element you want to append to
$descBox = $dom->getElementsByTagName('body')[0];
//create the fragment
$fragment = $dom->createDocumentFragment();
//add content to fragment
$fragment->appendXML($apistring);
//actually append the element
//$descBox->appendChild($fragment);
$origH3 = $dom->getElementsByTagName('head')[0];
$origH3->appendChild($fragment);
echo $dom->saveHTML();
?>
+178
View File
@@ -0,0 +1,178 @@
<?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;
}
?>