showinframes.php 3.8 KB

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