showinframes.php 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. //window.alert(Score);
  38. } else {
  39. 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;
  40. }
  41. }
  42. }
  43. function Finish() {
  44. mySaveScore();
  45. // Code added - end
  46. ";
  47. $newcontent = str_replace($mit, $js_content, $content);
  48. $prehref = "<!-- BeginTopNavButtons -->";
  49. $posthref = "<!-- BeginTopNavButtons -->";
  50. $newcontent = str_replace($prehref, $posthref, $newcontent);
  51. if (CheckSubFolder($full_file_path.$user_id.'.t.html') == 0) {
  52. $newcontent = ReplaceImgTag($newcontent);
  53. }
  54. } else {
  55. $newcontent = $content;
  56. }
  57. WriteFileCont($full_file_path.$user_id.'.t.html', $newcontent);
  58. $doc_url = GetFolderPath($doc_url).urlencode(basename($doc_url));
  59. $documentPath= api_get_path(SYS_COURSE_PATH).$_course['path']."/document";
  60. $my_file = Security::remove_XSS($_GET['file']);
  61. $my_file = str_replace(array('../', '\\..', '\\0', '..\\'), array('', '', '', ''),urldecode($my_file));
  62. $title = GetQuizName($my_file, $documentPath);
  63. if ($title =='') {
  64. $title = basename($my_file);
  65. }
  66. $nameTools = $title;
  67. $noPHP_SELF = true;
  68. $htmlHeadXtra[] = '
  69. <script>
  70. $(document).ready( function(){
  71. var height = $(this).innerHeight() - 20;
  72. $("#hotpotatoe").css("height", height)
  73. });
  74. </script>';
  75. $interbreadcrumb[]= array ("url"=>"./exercise.php", "name"=> get_lang('Exercises'));
  76. if ($origin == 'learnpath') {
  77. Display::display_reduced_header($nameTools,"Exercise");
  78. } else {
  79. Display::display_header($nameTools,"Exercise");
  80. }
  81. $url = $document_web_path.$doc_url.$user_id.'.t.html?time='.Security::remove_XSS($time);
  82. echo '<iframe id="hotpotatoe" width="100%" frameborder="0" src="'.$url.'"></iframe>';
  83. echo '</body></html>';
  84. exit;