show_content.php 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @author jmontoya
  5. *
  6. * @package chamilo.document
  7. */
  8. /**
  9. * Code
  10. */
  11. /* INITIALIZATION */
  12. $language_file[] = 'document';
  13. require_once '../inc/global.inc.php';
  14. // Protection
  15. api_protect_course_script();
  16. $noPHP_SELF = true;
  17. $header_file = isset($_GET['file']) ? Security::remove_XSS($_GET['file']) : null;
  18. $document_id = intval($_GET['id']);
  19. $course_info = api_get_course_info();
  20. $course_code = api_get_course_id();
  21. if (empty($course_info)) {
  22. api_not_allowed(true);
  23. }
  24. //Generate path
  25. if (!$document_id) {
  26. $document_id = DocumentManager::get_document_id($course_info, $header_file);
  27. }
  28. $document_data = DocumentManager::get_document_data_by_id($document_id, $course_code);
  29. if (empty($document_data)) {
  30. api_not_allowed(true);
  31. }
  32. $header_file = $document_data['path'];
  33. $name_to_show = Text::cut($header_file, 80);
  34. $path_array = explode('/', str_replace('\\', '/', $header_file));
  35. $path_array = array_map('urldecode', $path_array);
  36. $header_file = implode('/', $path_array);
  37. $file = Security::remove_XSS(urldecode($document_data['path']));
  38. $file_root = $course_info['path'].'/document'.str_replace('%2F', '/', $file);
  39. $file_url_sys = api_get_path(SYS_COURSE_PATH).$file_root;
  40. $file_url_web = api_get_path(WEB_COURSE_PATH).$file_root;
  41. if (!file_exists($file_url_sys)) {
  42. api_not_allowed(true);
  43. }
  44. if (is_dir($file_url_sys)) {
  45. api_not_allowed(true);
  46. }
  47. //Check user visibility
  48. //$is_visible = DocumentManager::is_visible_by_id($document_id, $course_info, api_get_session_id(), api_get_user_id());
  49. $is_visible = DocumentManager::check_visibility_tree($document_id, api_get_course_id(), api_get_session_id(), api_get_user_id());
  50. if (!api_is_allowed_to_edit() && !$is_visible) {
  51. api_not_allowed(true);
  52. }
  53. //TODO:clean all code
  54. /* Main section */
  55. header('Expires: Wed, 01 Jan 1990 00:00:00 GMT');
  56. //header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  57. header('Last-Modified: Wed, 01 Jan 2100 00:00:00 GMT');
  58. header('Cache-Control: no-cache, must-revalidate');
  59. header('Pragma: no-cache');
  60. $browser_display_title = 'Documents - '.Security::remove_XSS($_GET['cidReq']).' - '.$file;
  61. $file_url_web = api_get_path(WEB_COURSE_PATH).$_course['path'].'/document'.$header_file.'?'.api_get_cidreq();
  62. $pathinfo = pathinfo($header_file);
  63. if ($pathinfo['extension']=='wav' && preg_match('/_chnano_.wav/i', $file_url_web) && api_get_setting('enable_nanogong') == 'true'){
  64. echo '<div align="center">';
  65. echo '<br/>';
  66. echo '<applet id="applet" archive="../inc/lib/nanogong/nanogong.jar" code="gong.NanoGong" width="160" height="40" >';
  67. echo '<param name="SoundFileURL" value="'.$file_url_web.'" />';
  68. echo '<param name="ShowSaveButton" value="false" />';
  69. echo '<param name="ShowTime" value="true" />';
  70. echo '<param name="ShowRecordButton" value="false" />';
  71. echo '</applet>';
  72. echo '</div>';
  73. } else {
  74. if ($pathinfo['extension']=='swf') { $width='83%'; $height='83%';} else {$width='100%'; $height='100%';}
  75. echo '<iframe border="0" frameborder="0" scrolling="no" style="width:'.$width.'; height:'.$height.';background-color:#ffffff;" id="mainFrame" name="mainFrame" src="'.$file_url_web.'?'.api_get_cidreq().'&amp;rand='.mt_rand(1, 1000).'"></iframe>';
  76. }