showinframes.php 4.6 KB

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