showinframes.php 3.7 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 '../inc/global.inc.php';
  9. require_once api_get_path(SYS_CODE_PATH).'exercice/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_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;
  37. } else {
  38. 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;
  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[] = '
  68. <script>
  69. $(document).ready( function(){
  70. var height = $(this).innerHeight( - 20;
  71. if (height < 0) {
  72. height = "95%";
  73. }
  74. $("#hotpotatoe").css("height", height);
  75. });
  76. </script>';
  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" width="100%" frameborder="0" src="'.$url.'"></iframe>';
  85. echo '</body></html>';
  86. exit;