showinframes.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Code library for HotPotatoes integration.
  5. *
  6. * @package chamilo.exercise
  7. *
  8. * @author Istvan Mandak
  9. */
  10. require_once __DIR__.'/../inc/global.inc.php';
  11. api_protect_course_script(true);
  12. require_once api_get_path(SYS_CODE_PATH).'exercise/hotpotatoes.lib.php';
  13. $_course = api_get_course_info();
  14. $time = time();
  15. $doc_url = str_replace(['../', '\\', '\\0', '..'], ['', '', '', ''], urldecode($_GET['file']));
  16. $cid = api_get_course_id();
  17. $document_path = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
  18. $document_web_path = api_get_path(WEB_COURSE_PATH).$_course['path'].'/document';
  19. $origin = api_get_origin();
  20. $learnpath_id = isset($_REQUEST['learnpath_id']) ? $_REQUEST['learnpath_id'] : null;
  21. $learnpath_item_id = isset($_REQUEST['learnpath_item_id']) ? $_REQUEST['learnpath_item_id'] : null;
  22. $time = isset($_REQUEST['time']) ? $_REQUEST['time'] : null;
  23. $lpViewId = isset($_REQUEST['lp_view_id']) ? $_REQUEST['lp_view_id'] : null;
  24. $user_id = api_get_user_id();
  25. $full_file_path = $document_path.$doc_url;
  26. my_delete($full_file_path.$user_id.'.t.html');
  27. $content = ReadFileCont($full_file_path.$user_id.'.t.html');
  28. if ($content == '') {
  29. $content = ReadFileCont($full_file_path);
  30. // Do not move this like:
  31. $mit = "function Finish(){";
  32. $js_content = "
  33. // Code added - start
  34. var SaveScoreVariable = 0;
  35. function mySaveScore() {
  36. if (SaveScoreVariable==0) {
  37. SaveScoreVariable = 1;
  38. if (C.ie) {
  39. document.location.href = '".api_get_path(WEB_CODE_PATH)."exercise/savescores.php?lp_view_id=$lpViewId&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;
  40. } else {
  41. window.location.href = '".api_get_path(WEB_CODE_PATH)."exercise/savescores.php?lp_view_id=$lpViewId&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;
  42. }
  43. }
  44. }
  45. function Finish() {
  46. mySaveScore();
  47. // Code added - end
  48. ";
  49. $newcontent = str_replace($mit, $js_content, $content);
  50. $prehref = "<!-- BeginTopNavButtons -->";
  51. $posthref = "<!-- BeginTopNavButtons -->";
  52. $newcontent = str_replace($prehref, $posthref, $newcontent);
  53. if (CheckSubFolder($full_file_path.$user_id.'.t.html') == 0) {
  54. $newcontent = ReplaceImgTag($newcontent);
  55. }
  56. } else {
  57. $newcontent = $content;
  58. }
  59. WriteFileCont($full_file_path.$user_id.'.t.html', $newcontent);
  60. $doc_url = GetFolderPath($doc_url).urlencode(basename($doc_url));
  61. $documentPath = api_get_path(SYS_COURSE_PATH).$_course['path']."/document";
  62. $my_file = Security::remove_XSS($_GET['file']);
  63. $my_file = str_replace(['../', '\\..', '\\0', '..\\'], ['', '', '', ''], urldecode($my_file));
  64. $title = GetQuizName($my_file, $documentPath);
  65. if ($title == '') {
  66. $title = basename($my_file);
  67. }
  68. $nameTools = $title;
  69. $htmlHeadXtra[] = <<<HTML
  70. <script>
  71. function setHeight()
  72. {
  73. var iframe = document.getElementById('hotpotatoe');
  74. iframe.height = 800;
  75. var maxheight = $(iframe.contentDocument.body).outerHeight(true);
  76. iframe.height = maxheight
  77. $(iframe.contentDocument.body).children().each(function() {
  78. // If this elements height is bigger than the biggestHeight
  79. var tempheight = $(this)["0"].offsetHeight + $(this)["0"].offsetTop;
  80. if (tempheight > maxheight) {
  81. // Set the maxheight to this Height
  82. maxheight = tempheight;
  83. }
  84. });
  85. iframe.height = maxheight;
  86. }
  87. $(function() {
  88. var iframe = document.getElementById('hotpotatoe');
  89. iframe.onload = function () {
  90. // this.height = $(this.contentDocument.body).outerHeight(true)
  91. setTimeout(function(){
  92. setHeight();
  93. }, 1750);
  94. };
  95. });
  96. </script>
  97. HTML;
  98. $interbreadcrumb[] = ["url" => './exercise.php?'.api_get_cidreq(), 'name' => get_lang('Exercises')];
  99. if ($origin == 'learnpath') {
  100. Display::display_reduced_header($nameTools, "Exercise");
  101. } else {
  102. Display::display_header($nameTools, "Exercise");
  103. }
  104. $url = $document_web_path.$doc_url.$user_id.'.t.html?time='.intval($time);
  105. echo '<iframe id="hotpotatoe" name="hotpotatoe" width="100%" height="100%" frameborder="0" src="'.$url.'"></iframe>';
  106. if ($origin == 'learnpath') {
  107. Display::display_reduced_footer();
  108. } else {
  109. Display::display_footer();
  110. }