/** * fix_js_CheckFinished * * @param xxx $str (passed by reference) * @param xxx $start * @param xxx $length */ function fix_js_CheckFinished(&$str, $start, $length) { $substr = substr($str, $start, $length); $search = ' var AllDone = true;'; if ($pos = strpos($substr, $search)) { $insert = '' . "\tvar CountWrong = 0;\n" . "\tvar TotalWeighting = 0;\n" . "\tvar BestPossibleScore = 0;\n"; $substr = substr_replace($substr, $insert, $pos, 0); } $search = ' if (State[QNum][0] < 0){'; if ($pos = strpos($substr, $search)) { $insert = '' . "\t\t\tif (State[QNum][2] && State[QNum][0] <= 0){\n" . "\t\t\t\tCountWrong++;\n" . "\t\t\t}\n" . "\t\t\tTotalWeighting += I[QNum][0]\n" . "\t\t\tif (State[QNum][0] >= 0){\n" . "\t\t\t\tBestPossibleScore += (I[QNum][0] * State[QNum][0]);\n" . "\t\t\t} else {\n" . "\t\t\t\tBestPossibleScore += I[QNum][0];\n" . "\t\t\t}\n"; $substr = substr_replace($substr, $insert, $pos, 0); } $search = ' if (AllDone == true){'; if ($pos = strpos($substr, $search)) { $insert = '' . "\tif (typeof(ForceQuizEvent)=='undefined') {\n" . "\t\tif (maximumWrong && CountWrong > maximumWrong) {\n" . "\t\t\tForceQuizEvent = 3;\n" . "\t\t}\n" . "\t\tif (TotalWeighting > 0) {\n" . "\t\t\tBestPossibleScore = Math.floor((BestPossibleScore/TotalWeighting)*100);\n" . "\t\t} else {\n" . "\t\t\tBestPossibleScore = 100;\n" . "\t\t}\n" . "\t\tif (minimumScore && BestPossibleScore < minimumScore) {\n" . "\t\t\tForceQuizEvent = 3;\n" . "\t\t}\n" . "\t}\n"; $substr = substr_replace($substr, $insert, $pos, 0); } parent::fix_js_CheckFinished($substr, 0, strlen($substr)); $str = substr_replace($str, $substr, $start, $length); }