showinframes.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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_once '../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 = isset($_REQUEST['time']) ? $_REQUEST['time'] : null ;
  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. $url = api_get_path(WEB_CODE_PATH)."exercice/savescores.php?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";
  28. $content = ReadFileCont($full_file_path);
  29. $mit = "function Finish(){";
  30. $js_content = "
  31. //Code added - start
  32. var SaveScoreVariable = 0;
  33. function mySaveScore() {
  34. if (SaveScoreVariable==0) {
  35. SaveScoreVariable = 1;
  36. if (C.ie) {
  37. document.location.href = '".$url.";
  38. //window.alert(Score);
  39. } else {
  40. window.location.href = '".$url.";
  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(array('../', '\\..', '\\0', '..\\'), array('', '', '', ''), urldecode($my_file));
  63. $title = GetQuizName($my_file, $documentPath);
  64. if ($title == '') {
  65. $title = basename($my_file);
  66. }
  67. $nameTools = $title;
  68. $noPHP_SELF = true;
  69. if (isset($_SESSION['gradebook'])) {
  70. $gradebook = $_SESSION['gradebook'];
  71. }
  72. if (!empty($gradebook) && $gradebook == 'view') {
  73. $interbreadcrumb[] = array(
  74. 'url' => '../gradebook/'.$_SESSION['gradebook_dest'],
  75. 'name' => get_lang('ToolGradebook')
  76. );
  77. }
  78. $htmlHeadXtra[] = '
  79. <script>
  80. $(document).ready( function(){
  81. var height = $(this).innerHeight() - 20;
  82. $("#hotpotatoe").css("height", height)
  83. });
  84. </script>';
  85. $interbreadcrumb[] = array("url" => "./exercice.php", "name" => get_lang('Exercices'));
  86. if ($origin == 'learnpath') {
  87. Display::display_reduced_header($nameTools, "Exercise");
  88. } else {
  89. Display::display_header($nameTools, "Exercise");
  90. }
  91. $url = $document_web_path.$doc_url.$user_id.'.t.html?time='.Security::remove_XSS($time);
  92. echo '<iframe id="hotpotatoe" width="100%" frameborder="0" src="'.$url.'"></iframe>';
  93. echo '</body></html>';
  94. Display::display_footer();
  95. exit;