record_audio.php 4.5 KB

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