$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 = "\n //Code added - start\n\n var SaveScoreVariable = 0;\n function mySaveScore() {\n if (SaveScoreVariable==0) {\n SaveScoreVariable = 1;\n if (C.ie) {\n document.location.href = '" . $url . ";\n //window.alert(Score);\n } else {\n window.location.href = '" . $url . ";\n }\n }\n }\n function Finish() {\n mySaveScore();\n\n //Code added - end\n "; $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')); }
/** * Checks if there are subfolders. * @param string Path * @return integer 1 if a subfolder was found, 0 otherwise */ function CheckSubFolder($path) { $folder = GetFolderPath($path); $dflag = 0; if ($dir = @opendir($folder)) { while (($file = readdir($dir)) !== false) { if ($file != '.') { if ($file != '..') { $full_name = $folder . '/' . $file; if (is_dir($full_name)) { $dflag = 1; // first directory } } } } } return $dflag; }