record_audio.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use ChamiloSession as Session;
  4. /**
  5. * This file allows record audio files.
  6. *
  7. * @package chamilo.document
  8. */
  9. require_once __DIR__.'/../inc/global.inc.php';
  10. $this_section = SECTION_COURSES;
  11. $groupRights = Session::read('group_member_with_upload_rights');
  12. $nameTools = get_lang('VoiceRecord');
  13. api_protect_course_script();
  14. api_block_anonymous_users();
  15. $document_data = DocumentManager::get_document_data_by_id(
  16. $_GET['id'],
  17. api_get_course_id(),
  18. true
  19. );
  20. if (empty($document_data)) {
  21. if (api_is_in_group()) {
  22. $group_properties = GroupManager::get_group_properties(
  23. api_get_group_id()
  24. );
  25. $document_id = DocumentManager::get_document_id(
  26. api_get_course_info(),
  27. $group_properties['directory']
  28. );
  29. $document_data = DocumentManager::get_document_data_by_id(
  30. $document_id,
  31. api_get_course_id()
  32. );
  33. }
  34. }
  35. $document_id = $document_data['id'];
  36. $dir = $document_data['path'];
  37. //make some vars
  38. $wamidir = $dir;
  39. if ($wamidir == "/") {
  40. $wamidir = '';
  41. }
  42. $wamiurlplay = api_get_path(WEB_COURSE_PATH).api_get_course_path().'/document'.$wamidir."/";
  43. $groupId = api_get_group_id();
  44. $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
  45. // Please, do not modify this dirname formatting
  46. if (strstr($dir, '..')) {
  47. $dir = '/';
  48. }
  49. if ($dir[0] == '.') {
  50. $dir = substr($dir, 1);
  51. }
  52. if ($dir[0] != '/') {
  53. $dir = '/'.$dir;
  54. }
  55. if ($dir[strlen($dir) - 1] != '/') {
  56. $dir .= '/';
  57. }
  58. $filepath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document'.$dir;
  59. if (!is_dir($filepath)) {
  60. $filepath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document/';
  61. $dir = '/';
  62. }
  63. //groups //TODO: clean
  64. if (!empty($groupId)) {
  65. $interbreadcrumb[] = ["url" => "../group/group_space.php?".api_get_cidreq(), "name" => get_lang('GroupSpace')];
  66. $group = GroupManager :: get_group_properties($groupId);
  67. $path = explode('/', $dir);
  68. if ('/'.$path[1] != $group['directory']) {
  69. api_not_allowed(true);
  70. }
  71. }
  72. $interbreadcrumb[] = ["url" => "./document.php?id=".$document_id.'&'.api_get_cidreq(), "name" => get_lang('Documents')];
  73. if (!api_is_allowed_in_course()) {
  74. api_not_allowed(true);
  75. }
  76. if (!($is_allowed_to_edit || $groupRights ||
  77. DocumentManager::is_my_shared_folder(
  78. api_get_user_id(),
  79. Security::remove_XSS($dir),
  80. api_get_session_id()
  81. ))
  82. ) {
  83. api_not_allowed(true);
  84. }
  85. /* Header */
  86. Event::event_access_tool(TOOL_DOCUMENT);
  87. $display_dir = $dir;
  88. if (isset($group)) {
  89. $display_dir = explode('/', $dir);
  90. unset($display_dir[0]);
  91. unset($display_dir[1]);
  92. $display_dir = implode('/', $display_dir);
  93. }
  94. // Interbreadcrumb for the current directory root path
  95. $counter = 0;
  96. if (isset($document_data['parents'])) {
  97. foreach ($document_data['parents'] as $document_sub_data) {
  98. //fixing double group folder in breadcrumb
  99. if (api_get_group_id()) {
  100. if ($counter == 0) {
  101. $counter++;
  102. continue;
  103. }
  104. }
  105. $interbreadcrumb[] = [
  106. 'url' => $document_sub_data['document_url'],
  107. 'name' => $document_sub_data['title'],
  108. ];
  109. $counter++;
  110. }
  111. }
  112. //make some vars
  113. $wamiuserid = api_get_user_id();
  114. $htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_JS_PATH).'rtc/RecordRTC.js"></script>';
  115. $htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'wami-recorder/recorder.js"></script>';
  116. $htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'wami-recorder/gui.js"></script>';
  117. $htmlHeadXtra[] = '<script type="text/javascript" src="'.api_get_path(WEB_LIBRARY_PATH).'swfobject/swfobject.js"></script>';
  118. $htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'swfobject/swfobject.js"></script>';
  119. $htmlHeadXtra[] = api_get_js('record_audio/record_audio.js');
  120. $actions = Display::toolbarButton(
  121. get_lang('BackTo').' '.get_lang('DocumentsOverview'),
  122. 'document.php?'.api_get_cidreq()."&id=$document_id",
  123. 'arrow-left',
  124. 'default',
  125. [],
  126. false
  127. );
  128. $template = new Template($nameTools);
  129. $template->assign('directory', $wamidir);
  130. $template->assign('user_id', api_get_user_id());
  131. $layout = $template->get_template('document/record_audio.tpl');
  132. $content = $template->fetch($layout);
  133. $template->assign(
  134. 'actions',
  135. Display::toolbarAction('toolbar', [$actions])
  136. );
  137. $template->assign('content', $content);
  138. $template->display_one_col_template();