123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- <?php
- /* For licensing terms, see /license.txt */
- /**
- * Code library for HotPotatoes integration.
- * @package chamilo.exercise
- * @author Istvan Mandak
- */
- /**
- * Included libraries
- */
- require_once '../inc/global.inc.php';
- require_once api_get_path(SYS_CODE_PATH).'exercice/hotpotatoes.lib.php';
- $time = time();
- $doc_url = str_replace(array('../', '\\', '\\0', '..'), array('', '', '', ''), urldecode($_GET['file']));
- $cid = api_get_course_id();
- $document_path = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
- $document_web_path = api_get_path(WEB_COURSE_PATH).$_course['path'].'/document';
- $origin = $_REQUEST['origin'];
- $learnpath_id = $_REQUEST['learnpath_id'];
- $learnpath_item_id = $_REQUEST['learnpath_item_id'];
- $time = isset($_REQUEST['time']) ? $_REQUEST['time'] : null ;
- $user_id = api_get_user_id();
- $full_file_path = $document_path.$doc_url;
- FileManager::my_delete($full_file_path.$user_id.'.t.html');
- $content = ReadFileCont($full_file_path.$user_id.'.t.html');
- if ($content == '') {
- $url = api_get_path(WEB_CODE_PATH)."exercice/savescores.php?origin=$origin&learnpath_id=$learnpath_id&learnpath_item_id=$learnpath_item_id&time=".Security::remove_XSS($time)."&test=".$doc_url."&uid=".$user_id."&cid=".$cid."&score='+Score";
- $content = ReadFileCont($full_file_path);
- $mit = "function Finish(){";
- $js_content = "
- //Code added - start
- var SaveScoreVariable = 0;
- function mySaveScore() {
- if (SaveScoreVariable==0) {
- SaveScoreVariable = 1;
- if (C.ie) {
- document.location.href = '".$url.";
- //window.alert(Score);
- } else {
- window.location.href = '".$url.";
- }
- }
- }
- function Finish() {
- mySaveScore();
- //Code added - end
- ";
- $newcontent = str_replace($mit, $js_content, $content);
- $prehref = "<!-- BeginTopNavButtons -->";
- $posthref = "<!-- BeginTopNavButtons -->";
- $newcontent = str_replace($prehref, $posthref, $newcontent);
- if (CheckSubFolder($full_file_path.$user_id.'.t.html') == 0) {
- $newcontent = ReplaceImgTag($newcontent);
- }
- } else {
- $newcontent = $content;
- }
- WriteFileCont($full_file_path.$user_id.'.t.html', $newcontent);
- $doc_url = GetFolderPath($doc_url).urlencode(basename($doc_url));
- $documentPath = api_get_path(SYS_COURSE_PATH).$_course['path']."/document";
- $my_file = Security::remove_XSS($_GET['file']);
- $my_file = str_replace(array('../', '\\..', '\\0', '..\\'), array('', '', '', ''), urldecode($my_file));
- $title = GetQuizName($my_file, $documentPath);
- if ($title == '') {
- $title = basename($my_file);
- }
- $nameTools = $title;
- $noPHP_SELF = true;
- if (isset($_SESSION['gradebook'])) {
- $gradebook = $_SESSION['gradebook'];
- }
- if (!empty($gradebook) && $gradebook == 'view') {
- $interbreadcrumb[] = array(
- 'url' => '../gradebook/'.$_SESSION['gradebook_dest'],
- 'name' => get_lang('ToolGradebook')
- );
- }
- $htmlHeadXtra[] = '
- <script>
- $(document).ready( function(){
- var height = $(this).innerHeight() - 20;
- $("#hotpotatoe").css("height", height)
- });
- </script>';
- $interbreadcrumb[] = array("url" => "./exercice.php", "name" => get_lang('Exercices'));
- if ($origin == 'learnpath') {
- Display::display_reduced_header($nameTools, "Exercise");
- } else {
- Display::display_header($nameTools, "Exercise");
- }
- $url = $document_web_path.$doc_url.$user_id.'.t.html?time='.Security::remove_XSS($time);
- echo '<iframe id="hotpotatoe" width="100%" frameborder="0" src="'.$url.'"></iframe>';
- echo '</body></html>';
- Display::display_footer();
- exit;
|