showinframes.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Code library for HotPotatoes integration.
  5. * @package chamilo.exercise
  6. * @author Istvan Mandak
  7. */
  8. /**
  9. * Included libraries
  10. */
  11. require '../inc/global.inc.php';
  12. require_once api_get_path(SYS_CODE_PATH).'exercice/hotpotatoes.lib.php';
  13. $time = time();
  14. $doc_url = str_replace(array('../', '\\', '\\0', '..'), array('', '', '', ''), urldecode($_GET['file']));
  15. $cid = api_get_course_id();
  16. $document_path = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
  17. $document_web_path = api_get_path(WEB_COURSE_PATH).$_course['path'].'/document';
  18. $origin = $_REQUEST['origin'];
  19. $learnpath_id = $_REQUEST['learnpath_id'];
  20. $learnpath_item_id = $_REQUEST['learnpath_item_id'];
  21. $time = $_REQUEST['time'];
  22. $user_id = api_get_user_id();
  23. $full_file_path = $document_path.$doc_url;
  24. FileManager::my_delete($full_file_path.$user_id.'.t.html');
  25. $content = ReadFileCont($full_file_path.$user_id.'.t.html');
  26. if ($content == '') {
  27. $content = ReadFileCont($full_file_path);
  28. $mit = "function Finish(){";
  29. $js_content = "
  30. //Code added - start
  31. var SaveScoreVariable = 0;
  32. function mySaveScore() {
  33. if (SaveScoreVariable==0) {
  34. SaveScoreVariable = 1;
  35. if (C.ie) {
  36. document.location.href = '".api_get_path(
  37. WEB_PATH
  38. )."main/exercice/savescores.php?origin=$origin&learnpath_id=$learnpath_id&learnpath_item_id=$learnpath_item_id&time=".Security::remove_XSS(
  39. $time
  40. )."&test=".$doc_url."&uid=".$user_id."&cid=".$cid."&score='+Score;
  41. //window.alert(Score);
  42. } else {
  43. window.location.href = '".api_get_path(
  44. WEB_PATH
  45. )."main/exercice/savescores.php?origin=$origin&learnpath_id=$learnpath_id&learnpath_item_id=$learnpath_item_id&time=".Security::remove_XSS(
  46. $time
  47. )."&test=".$doc_url."&uid=".$user_id."&cid=".$cid."&score='+Score;
  48. }
  49. }
  50. }
  51. function Finish(){
  52. mySaveScore();
  53. //Code added - end
  54. ";
  55. $newcontent = str_replace($mit, $js_content, $content);
  56. $prehref = "<!-- BeginTopNavButtons -->";
  57. $posthref = "<!-- BeginTopNavButtons -->";
  58. $newcontent = str_replace($prehref, $posthref, $newcontent);
  59. if (CheckSubFolder($full_file_path.$user_id.'.t.html') == 0) {
  60. $newcontent = ReplaceImgTag($newcontent);
  61. }
  62. } else {
  63. $newcontent = $content;
  64. }
  65. WriteFileCont($full_file_path.$user_id.'.t.html', $newcontent);
  66. $doc_url = GetFolderPath($doc_url).urlencode(basename($doc_url));
  67. $documentPath = api_get_path(SYS_COURSE_PATH).$_course['path']."/document";
  68. $my_file = Security::remove_XSS($_GET['file']);
  69. $my_file = str_replace(array('../', '\\..', '\\0', '..\\'), array('', '', '', ''), urldecode($my_file));
  70. $title = GetQuizName($my_file, $documentPath);
  71. if ($title == '') {
  72. $title = basename($my_file);
  73. }
  74. $nameTools = $title;
  75. $noPHP_SELF = true;
  76. if (isset($_SESSION['gradebook'])) {
  77. $gradebook = $_SESSION['gradebook'];
  78. }
  79. if (!empty($gradebook) && $gradebook == 'view') {
  80. $interbreadcrumb[] = array(
  81. 'url' => '../gradebook/'.$_SESSION['gradebook_dest'],
  82. 'name' => get_lang('ToolGradebook')
  83. );
  84. }
  85. $htmlHeadXtra[] = '
  86. <script>
  87. $(document).ready( function(){
  88. var height = $(this).innerHeight() - 20;
  89. $("#hotpotatoe").css("height", height)
  90. });
  91. </script>';
  92. $interbreadcrumb[] = array("url" => "./exercice.php", "name" => get_lang('Exercices'));
  93. if ($origin == 'learnpath') {
  94. Display::display_reduced_header($nameTools, "Exercise");
  95. } else {
  96. Display::display_header($nameTools, "Exercise");
  97. }
  98. $url = $document_web_path.$doc_url.$user_id.'.t.html?time='.Security::remove_XSS($time);
  99. echo '<iframe style="overflow:hidden" id="hotpotatoe" width="100%" frameborder="0" src="'.$url.'"></iframe>';
  100. echo '</body></html>';
  101. exit;