showinframes.php 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 '../inc/global.inc.php';
  9. require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
  10. require_once api_get_path(SYS_CODE_PATH).'exercice/hotpotatoes.lib.php';
  11. $_course = api_get_course_info();
  12. $time = time();
  13. $doc_url = str_replace(array('../', '\\', '\\0', '..'), array('', '', '', ''), urldecode($_GET['file']));
  14. $cid = api_get_course_id();
  15. $document_path = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document';
  16. $document_web_path = api_get_path(WEB_COURSE_PATH) . $_course['path'] . '/document';
  17. $origin = isset($_REQUEST['origin']) ? $_REQUEST['origin'] : null;
  18. $learnpath_id = isset($_REQUEST['learnpath_id']) ? $_REQUEST['learnpath_id'] : null;
  19. $learnpath_item_id = isset($_REQUEST['learnpath_item_id']) ? $_REQUEST['learnpath_item_id'] : null;
  20. $time = isset($_REQUEST['time']) ? $_REQUEST['time'] : null;
  21. $lpViewId = isset($_REQUEST['lp_view_id']) ? $_REQUEST['lp_view_id'] : null;
  22. $user_id = api_get_user_id();
  23. $full_file_path = $document_path.$doc_url;
  24. my_delete($full_file_path.$user_id.'.t.html');
  25. $content = ReadFileCont($full_file_path.$user_id.'.t.html');
  26. if ($content == '') {
  27. $content = ReadFileCont($full_file_path);
  28. // Do not move this like:
  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 = '".api_get_path(WEB_PATH)."main/exercice/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. //window.alert(Score);
  39. } else {
  40. window.location.href = '".api_get_path(WEB_PATH)."main/exercice/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(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. $htmlHeadXtra[] = '
  70. <script>
  71. $(document).ready( function(){
  72. var height = $(this).innerHeight() - 20;
  73. $("#hotpotatoe").css("height", height)
  74. });
  75. </script>';
  76. $interbreadcrumb[]= array ("url"=>"./exercice.php", "name"=> get_lang('Exercices'));
  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='.Security::remove_XSS($time);
  83. echo '<iframe id="hotpotatoe" width="100%" frameborder="0" src="'.$url.'"></iframe>';
  84. echo '</body></html>';
  85. exit;