record_audio.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This file allows creating new svg and png documents with an online editor.
  5. *
  6. * @package chamilo.document
  7. *
  8. * @author Juan Carlos Raña Trabado herodoto@telefonica.net
  9. * @since 5/mar/2011
  10. */
  11. require_once '../inc/global.inc.php';
  12. $_SESSION['whereami'] = 'document/voicerecord';
  13. $this_section = SECTION_COURSES;
  14. $nameTools = get_lang('VoiceRecord');
  15. api_protect_course_script();
  16. api_block_anonymous_users();
  17. $groupId = api_get_group_id();
  18. $document_data = array();
  19. if (isset($_GET['id'])) {
  20. $document_data = DocumentManager::get_document_data_by_id(
  21. $_GET['id'],
  22. api_get_course_id(),
  23. true
  24. );
  25. }
  26. if (empty($document_data)) {
  27. if (api_is_in_group()) {
  28. $group_properties = GroupManager::get_group_properties($groupId);
  29. $document_id = DocumentManager::get_document_id(api_get_course_info(), $group_properties['directory']);
  30. $document_data = DocumentManager::get_document_data_by_id($document_id, api_get_course_id());
  31. }
  32. }
  33. $document_id = $document_data['id'];
  34. $dir = $document_data['path'];
  35. $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
  36. // Please, do not modify this dirname formatting
  37. if (strstr($dir, '..')) {
  38. $dir = '/';
  39. }
  40. if ($dir[0] == '.') {
  41. $dir = substr($dir, 1);
  42. }
  43. if ($dir[0] != '/') {
  44. $dir = '/'.$dir;
  45. }
  46. if ($dir[strlen($dir) - 1] != '/') {
  47. $dir .= '/';
  48. }
  49. $filepath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document'.$dir;
  50. if (!is_dir($filepath)) {
  51. $filepath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document/';
  52. $dir = '/';
  53. }
  54. if (!empty($groupId)) {
  55. $interbreadcrumb[] = array ("url" => "../group/group_space.php?".api_get_cidreq(), "name" => get_lang('GroupSpace'));
  56. $group = GroupManager :: get_group_properties($groupId);
  57. $path = explode('/', $dir);
  58. if ('/'.$path[1] != $group['directory']) {
  59. api_not_allowed(true);
  60. }
  61. }
  62. $interbreadcrumb[] = array("url" => "./document.php?id=".$document_id.'&'.api_get_cidreq(), "name" => get_lang('Documents'));
  63. if (!$is_allowed_in_course) {
  64. api_not_allowed(true);
  65. }
  66. if (!($is_allowed_to_edit || $_SESSION['group_member_with_upload_rights'] ||
  67. DocumentManager::is_my_shared_folder(api_get_user_id(), Security::remove_XSS($dir),api_get_session_id()))) {
  68. api_not_allowed(true);
  69. }
  70. /* Header */
  71. Event::event_access_tool(TOOL_DOCUMENT);
  72. $display_dir = $dir;
  73. if (isset ($group)) {
  74. $display_dir = explode('/', $dir);
  75. unset ($display_dir[0]);
  76. unset ($display_dir[1]);
  77. $display_dir = implode('/', $display_dir);
  78. }
  79. // Interbreadcrumb for the current directory root path
  80. $counter = 0;
  81. if (isset($document_data['parents'])) {
  82. foreach($document_data['parents'] as $document_sub_data) {
  83. //fixing double group folder in breadcrumb
  84. if (api_get_group_id()) {
  85. if ($counter == 0) {
  86. $counter++;
  87. continue;
  88. }
  89. }
  90. $interbreadcrumb[] = array('url' => $document_sub_data['document_url'], 'name' => $document_sub_data['title']);
  91. $counter++;
  92. }
  93. }
  94. Display :: display_header($nameTools, 'Doc');
  95. echo '<div class="actions">';
  96. echo '<a href="document.php?'.api_get_cidreq().'&id='.$document_id.'">'.Display::return_icon('back.png',get_lang('BackTo').' '.get_lang('DocumentsOverview'),'',ICON_SIZE_MEDIUM).'</a>';
  97. echo '</div>';
  98. ?>
  99. <script type="text/javascript">
  100. function submitVoice() {
  101. //lang vars
  102. var lang_no_applet="<?php echo get_lang('NanogongNoApplet'); ?>";
  103. var lang_record_before_save="<?php echo get_lang('NanogongRecordBeforeSave'); ?>";
  104. var lang_give_a_title="<?php echo get_lang('NanogongGiveTitle'); ?>";
  105. var lang_failled_to_submit="<?php echo get_lang('NanogongFailledToSubmit'); ?>";
  106. var lang_submitted="<?php echo get_lang('NanogongSubmitted'); ?>";
  107. // user and group id
  108. var nano_user_id="<?php echo api_get_user_id(); ?>";
  109. var nano_group_id="<?php echo api_get_group_id(); ?>";
  110. var nano_session_id="<?php echo api_get_session_id(); ?>";
  111. //path, url and filename
  112. var filename = document.getElementById("audio_title").value+"_chnano_.wav";//adding name file, tag and extension
  113. var filename = filename.replace(/\s/g, "_");//replace spaces by _
  114. var filename = encodeURIComponent(filename);
  115. var filepath="<?php echo urlencode($filepath); ?>";
  116. var dir="<?php echo urlencode($dir); ?>";
  117. var course_code="<?php echo urlencode($course_code); ?>";
  118. //
  119. var urlnanogong="../inc/lib/nanogong/receiver.php?filename="+filename+"&filepath="+filepath+"&dir="+dir+"&course_code="+course_code+"&nano_group_id="+nano_group_id+"&nano_session_id="+nano_session_id+"&nano_user_id="+nano_user_id;
  120. var cookie="<?php echo 'ch_sid='.session_id(); ?>";
  121. //check
  122. var recorder
  123. if (!(recorder = document.getElementById("nanogong"))) {
  124. alert(lang_no_applet)
  125. return
  126. }
  127. var duration = parseInt(recorder.sendGongRequest("GetMediaDuration", "audio")) || 0
  128. if (duration <= 0) {
  129. alert(lang_record_before_save)
  130. return
  131. }
  132. if (!document.getElementById("audio_title").value) {
  133. alert(lang_give_a_title)
  134. return
  135. }
  136. //
  137. var applet = document.getElementById("nanogong");
  138. var ret = applet.sendGongRequest( "PostToForm", urlnanogong, "voicefile", cookie, "temp");//'PostToForm', postURL, inputname, cookie, filename
  139. if (ret == null) {
  140. alert(lang_failled_to_submit);
  141. } else {
  142. alert(lang_submitted+"\n"+ret);
  143. $("#status").attr('value', '1');
  144. }
  145. }
  146. </script>
  147. <?php
  148. echo '<div align="center">';
  149. Display::display_icon('microphone.png', get_lang('PressRecordButton'),'','128');
  150. echo '<br/>';
  151. echo '<applet id="nanogong" archive="'.api_get_path(WEB_LIBRARY_PATH).'nanogong/nanogong.jar" code="gong.NanoGong" width="250" height="95" ALIGN="middle">';
  152. //echo '<param name="ShowRecordButton" value="false" />'; // default true
  153. // echo '<param name="ShowSaveButton" value="false" />'; //you can save in local computer | (default true)
  154. //echo '<param name="ShowSpeedButton" value="false" />'; // default true
  155. //echo '<param name="ShowAudioLevel" value="false" />'; // it displays the audiometer | (default true)
  156. echo '<param name="ShowTime" value="true" />'; // default false
  157. //echo '<param name="Color" value="#C0E0FF" />'; // default #FFFFFF
  158. //echo '<param name="StartTime" value="10.5" />';
  159. //echo '<param name="EndTime" value="65" />';
  160. echo '<param name="AudioFormat" value="ImaADPCM" />';// ImaADPCM (more speed), Speex (more compression)|(default Speex)
  161. //echo '<param name="SamplingRate" value="32000" />';//Quality for ImaADPCM (low 8000, medium 11025, normal 22050, hight 44100) OR Quality for Speex (low 8000, medium 16000, normal 32000, hight 44100) | (default 44100)
  162. //echo '<param name="MaxDuration" value="60" />';
  163. //echo '<param name="SoundFileURL" value="http://somewhere.com/mysoundfile.wav" />';//load a file |(default "")
  164. echo '</applet>';
  165. echo '<form name="form_nanogong">';
  166. echo '<input placeholder="'.get_lang('InputNameHere').'" type="text" id="audio_title">';
  167. echo '<input id="status" type="hidden" name="status" value="0">';
  168. echo '<button class="upload" type="submit" value="'.get_lang('Send').'" onClick="submitVoice()" />'.get_lang('Send').'</button>';
  169. echo '</form>';
  170. echo '</div>';
  171. Display :: display_footer();