$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 = "\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";
/** * Gets the image parameters from an image path. * @param string File name * @param string File path * @param reference Reference to a list of image parameters (emptied, then used to return results) * @param reference Reference to a counter of images (emptied, then used to return results) */ function GetImgParams($fname, $fpath, &$imgparams, &$imgcount) { // Select img tags from context. $imgparams = array(); //phpinfo(); $contents = ReadFileCont("{$fpath}" . "{$fname}"); $matches = array(); preg_match_all('(<img .*>)', $contents, $matches); $imgcount = 0; while (list($int, $match) = each($matches)) { // Each match consists of a key and a value. while (list($key, $imgtag) = each($match)) { $imgname = GetImgName($imgtag); if ($imgname != '' && !in_array($imgname, $imgparams)) { array_push($imgparams, $imgname); // name (+ type) of the images in the html test $imgcount = $imgcount + 1; // number of images in the html test } } } }