showinframes.php 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. require_once api_get_path(SYS_CODE_PATH).'exercise/hotpotatoes.lib.php';
  9. $_course = api_get_course_info();
  10. $time = time();
  11. $doc_url = str_replace(array('../', '\\', '\\0', '..'), array('', '', '', ''), urldecode($_GET['file']));
  12. $cid = api_get_course_id();
  13. $document_path = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document';
  14. $document_web_path = api_get_path(WEB_COURSE_PATH) . $_course['path'] . '/document';
  15. $origin = isset($_REQUEST['origin']) ? $_REQUEST['origin'] : null;
  16. $learnpath_id = isset($_REQUEST['learnpath_id']) ? $_REQUEST['learnpath_id'] : null;
  17. $learnpath_item_id = isset($_REQUEST['learnpath_item_id']) ? $_REQUEST['learnpath_item_id'] : null;
  18. $time = isset($_REQUEST['time']) ? $_REQUEST['time'] : null;
  19. $lpViewId = isset($_REQUEST['lp_view_id']) ? $_REQUEST['lp_view_id'] : null;
  20. $user_id = api_get_user_id();
  21. $full_file_path = $document_path.$doc_url;
  22. my_delete($full_file_path.$user_id.'.t.html');
  23. $content = ReadFileCont($full_file_path.$user_id.'.t.html');
  24. if ($content == '') {
  25. $content = ReadFileCont($full_file_path);
  26. // Do not move this like:
  27. $mit = "function Finish(){";
  28. $js_content = "
  29. // Code added - start
  30. var SaveScoreVariable = 0;
  31. function mySaveScore() {
  32. if (SaveScoreVariable==0) {
  33. SaveScoreVariable = 1;
  34. if (C.ie) {
  35. 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;
  36. } else {
  37. 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;
  38. }
  39. }
  40. }
  41. function Finish() {
  42. mySaveScore();
  43. // Code added - end
  44. ";
  45. $newcontent = str_replace($mit, $js_content, $content);
  46. $prehref = "<!-- BeginTopNavButtons -->";
  47. $posthref = "<!-- BeginTopNavButtons -->";
  48. $newcontent = str_replace($prehref, $posthref, $newcontent);
  49. if (CheckSubFolder($full_file_path.$user_id.'.t.html') == 0) {
  50. $newcontent = ReplaceImgTag($newcontent);
  51. }
  52. } else {
  53. $newcontent = $content;
  54. }
  55. WriteFileCont($full_file_path.$user_id.'.t.html', $newcontent);
  56. $doc_url = GetFolderPath($doc_url).urlencode(basename($doc_url));
  57. $documentPath = api_get_path(SYS_COURSE_PATH).$_course['path']."/document";
  58. $my_file = Security::remove_XSS($_GET['file']);
  59. $my_file = str_replace(array('../', '\\..', '\\0', '..\\'), array('', '', '', ''), urldecode($my_file));
  60. $title = GetQuizName($my_file, $documentPath);
  61. if ($title =='') {
  62. $title = basename($my_file);
  63. }
  64. $nameTools = $title;
  65. $noPHP_SELF = true;
  66. $htmlHeadXtra[] = /** @lang HTML */<<<HTML
  67. <script>
  68. $(document).on('ready', function () {
  69. var iframe = document.getElementById('hotpotatoe');
  70. iframe.onload = function () {
  71. this.height = $(this.contentDocument.body).outerHeight(true)
  72. };
  73. });
  74. </script>
  75. HTML;
  76. $interbreadcrumb[]= array ("url"=>"./exercise.php", "name"=> get_lang('Exercises'));
  77. if ($origin == 'learnpath') {
  78. Display::display_reduced_header($nameTools, "Exercise");
  79. } else {
  80. Display::display_header($nameTools, "Exercise");
  81. }
  82. $url = $document_web_path.$doc_url.$user_id.'.t.html?time='.intval($time);
  83. echo '<iframe id="hotpotatoe" name="hotpotatoe" width="100%" height="100%" frameborder="0" src="'.$url.'"></iframe>';
  84. echo '</body></html>';
  85. exit;