record_audio.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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. /**
  12. * Code
  13. */
  14. /* INIT SECTION */
  15. // Name of the language file that needs to be included
  16. $language_file = array('document');
  17. require_once '../inc/global.inc.php';
  18. $_SESSION['whereami'] = 'document/voicerecord';
  19. $this_section = SECTION_COURSES;
  20. require_once api_get_path(SYS_CODE_PATH).'document/document.inc.php';
  21. require_once api_get_path(LIBRARY_PATH).'groupmanager.lib.php';
  22. $nameTools = get_lang('VoiceRecord');
  23. api_protect_course_script();
  24. api_block_anonymous_users();
  25. $document_data = DocumentManager::get_document_data_by_id($_GET['id'], api_get_course_id());
  26. if (empty($document_data)) {
  27. if (api_is_in_group()) {
  28. $group_properties = GroupManager::get_group_properties(api_get_group_id());
  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. //groups //TODO: clean
  55. if (isset ($_SESSION['_gid']) && $_SESSION['_gid'] != 0) {
  56. $req_gid = '&amp;gidReq='.$_SESSION['_gid'];
  57. $interbreadcrumb[] = array ("url" => "../group/group_space.php?gidReq=".$_SESSION['_gid'], "name" => get_lang('GroupSpace'));
  58. $noPHP_SELF = true;
  59. $to_group_id = $_SESSION['_gid'];
  60. $group = GroupManager :: get_group_properties($to_group_id);
  61. $path = explode('/', $dir);
  62. if ('/'.$path[1] != $group['directory']) {
  63. api_not_allowed(true);
  64. }
  65. }
  66. $interbreadcrumb[] = array ("url" => "./document.php?id=".$document_id.$req_gid, "name" => get_lang('Documents'));
  67. if (!$is_allowed_in_course) {
  68. api_not_allowed(true);
  69. }
  70. if (!($is_allowed_to_edit || $_SESSION['group_member_with_upload_rights'] || is_my_shared_folder(api_get_user_id(), Security::remove_XSS($dir),api_get_session_id()))) {
  71. api_not_allowed(true);
  72. }
  73. /* Header */
  74. event_access_tool(TOOL_DOCUMENT);
  75. $display_dir = $dir;
  76. if (isset ($group)) {
  77. $display_dir = explode('/', $dir);
  78. unset ($display_dir[0]);
  79. unset ($display_dir[1]);
  80. $display_dir = implode('/', $display_dir);
  81. }
  82. // Interbreadcrumb for the current directory root path
  83. // Copied from document.php
  84. $dir_array = explode('/', $dir);
  85. $array_len = count($dir_array);
  86. /*
  87. TODO:check and delete this code
  88. if (!$is_certificate_mode) {
  89. if ($array_len > 1) {
  90. if (empty($_SESSION['_gid'])) {
  91. $url_dir = 'document.php?&curdirpath=/';
  92. $interbreadcrumb[] = array('url' => $url_dir, 'name' => get_lang('HomeDirectory'));
  93. }
  94. }
  95. }
  96. */
  97. $dir_acum = '';
  98. for ($i = 0; $i < $array_len; $i++) {
  99. $url_dir = 'document.php?&curdirpath='.$dir_acum.$dir_array[$i];
  100. //Max char 80
  101. $url_to_who = cut($dir_array[$i],80);
  102. if ($is_certificate_mode) {
  103. $interbreadcrumb[] = array('url' => $url_dir.'&selectcat='.Security::remove_XSS($_GET['selectcat']), 'name' => $url_to_who);
  104. } else {
  105. $interbreadcrumb[] = array('url' => $url_dir, 'name' => $url_to_who);
  106. }
  107. $dir_acum .= $dir_array[$i].'/';
  108. }
  109. //
  110. Display :: display_header($nameTools, 'Doc');
  111. echo '<div class="actions">';
  112. echo '<a href="document.php?id='.$document_id.'">'.Display::return_icon('back.png',get_lang('BackTo').' '.get_lang('DocumentsOverview'),'','32').'</a>';
  113. echo '</div>';
  114. echo '<br/>';
  115. ?>
  116. <script language="JavaScript">
  117. function submitVoice() {
  118. //lang vars
  119. var lang_no_applet="<?php echo get_lang('NanogongNoApplet'); ?>";
  120. var lang_record_before_save="<?php echo get_lang('NanogongRecordBeforeSave'); ?>";
  121. var lang_give_a_title="<?php echo get_lang('NanogongGiveTitle'); ?>";
  122. var lang_failled_to_submit="<?php echo get_lang('NanogongFailledToSubmit'); ?>";
  123. var lang_submitted="<?php echo get_lang('NanogongSubmitted'); ?>";
  124. //path, url and filename
  125. var filename = document.getElementById("audio_title").value+".wav";
  126. var filename = filename.replace(/\s/g, "_");//replace spaces by _
  127. var filename = encodeURIComponent(filename);//TODO:implement a good encode into receiver.php
  128. var filepath="<?php echo urlencode($filepath); ?>";
  129. var dir="<?php echo urlencode($dir); ?>";
  130. var urlnanogong="../inc/lib/nanogong/receiver.php?filename="+filename+"&filepath="+filepath+"&dir="+dir;
  131. //check
  132. var recorder
  133. if (!(recorder = document.getElementById("nanogong")) || !(recorder.sendGongRequest)) {
  134. alert(lang_no_applet)
  135. return
  136. }
  137. var duration = parseInt(recorder.sendGongRequest("GetMediaDuration", "audio")) || 0
  138. if (duration <= 0) {
  139. alert(lang_record_before_save)
  140. return
  141. }
  142. if (!document.getElementById("audio_title").value) {
  143. alert(lang_give_a_title)
  144. return
  145. }
  146. //
  147. var applet = document.getElementById("nanogong");
  148. var ret = applet.sendGongRequest( "PostToForm", urlnanogong, "voicefile", "", "temp");//'PostToForm', postURL, inputname, cookie, filename
  149. if (ret == null) alert(lang_failled_to_submit); else alert(lang_submitted+"\n"+ret);
  150. }
  151. </script>
  152. <?php
  153. echo '<div align="center">';
  154. Display::display_icon('microphone.png', get_lang('PressRecordButton'),'','128');
  155. echo '<br/>';
  156. echo '<applet id="nanogong" archive="'.api_get_path(WEB_LIBRARY_PATH).'nanogong/nanogong.jar" code="gong.NanoGong" width="250" height="40" ALIGN="middle">';
  157. //echo '<param name="ShowRecordButton" value="false" />'; // default true
  158. // echo '<param name="ShowSaveButton" value="false" />'; //you can save in local computer | (default true)
  159. //echo '<param name="ShowSpeedButton" value="false" />'; // default true
  160. //echo '<param name="ShowAudioLevel" value="false" />'; // it displays the audiometer | (default true)
  161. echo '<param name="ShowTime" value="true" />'; // default false
  162. //echo '<param name="Color" value="#C0E0FF" />'; // default #FFFFFF
  163. //echo '<param name="StartTime" value="10.5" />';
  164. //echo '<param name="EndTime" value="65" />';
  165. echo '<param name="AudioFormat" value="ImaADPCM" />';// ImaADPCM (more speed), Speex (more compression)|(default Speex)
  166. //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)
  167. //echo '<param name="MaxDuration" value="60" />';
  168. //echo '<param name="SoundFileURL" value="http://somewhere.com/mysoundfile.wav" />';//load a file |(default "")
  169. echo '</applet>';
  170. //check browser support and load form
  171. $array_browser=api_browser_support('check_browser');
  172. if ($array_browser[0]=="Internet Explorer") {
  173. echo '<div style="width:250px; background-color:#FFEFA7">'.get_lang('BrowserNotSupportNanogongSend').'</div>';
  174. } else {
  175. echo '<form name="form_nanogong">';
  176. echo '<input type="text" id="audio_title">';
  177. echo '<button class="upload" type="submit" value="'.get_lang('Send').'" onClick="submitVoice()" />'.get_lang('Send').'</button>';
  178. echo '</form>';
  179. }
  180. echo '</div>';
  181. Display :: display_footer();