Files

199 lines
3.8 KiB
PHP

<?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();
?>