nanogong.lib.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /*
  4. *
  5. * Files are saved in the path:
  6. *
  7. * courses/XXX/exercises/(session_id)/(exercise_id)/(question_id)/(user_id)/
  8. *
  9. * The file name is composed with
  10. *
  11. * (course_id)/(session_id)/(user_id)/(exercise_id)/(question_id)/(exe_id).wav|mp3|ogg
  12. *
  13. *
  14. */
  15. class Nanogong {
  16. var $filename;
  17. var $store_filename;
  18. var $store_path;
  19. var $params;
  20. var $can_edit = false;
  21. /* Files allowed to upload */
  22. var $available_extensions = array('mp3', 'wav', 'ogg');
  23. public function __construct($params = array()) {
  24. $this->set_parameters($params);
  25. }
  26. function create_user_folder() {
  27. //COURSE123/exercises/session_id/exercise_id/question_id/user_id
  28. if (empty($this->store_path)) {
  29. return false;
  30. }
  31. //@todo use an array to create folders
  32. $folders_to_create = array();
  33. //Trying to create the courses/COURSE123/exercises/ dir just in case
  34. if (!is_dir($this->store_path)) {
  35. mkdir($this->store_path);
  36. }
  37. if (!is_dir($this->store_path.$this->session_id)) {
  38. mkdir($this->store_path.$this->session_id);
  39. }
  40. if (!empty($this->exercise_id) && !is_dir($this->store_path.$this->session_id.'/'.$this->exercise_id)) {
  41. mkdir($this->store_path.$this->session_id.'/'.$this->exercise_id);
  42. }
  43. if (!empty($this->question_id) && !is_dir($this->store_path.$this->session_id.'/'.$this->exercise_id.'/'.$this->question_id)) {
  44. mkdir($this->store_path.$this->session_id.'/'.$this->exercise_id.'/'.$this->question_id);
  45. }
  46. if (!empty($this->user_id) && !is_dir($this->store_path.$this->session_id.'/'.$this->exercise_id.'/'.$this->question_id.'/'.$this->user_id)) {
  47. mkdir($this->store_path.$this->session_id.'/'.$this->exercise_id.'/'.$this->question_id.'/'.$this->user_id);
  48. }
  49. }
  50. /**
  51. * Setting parameters: course id, session id, etc
  52. * @param array
  53. */
  54. function set_parameters($params = array()) {
  55. //Setting course id
  56. if (isset($params['course_id'])) {
  57. $this->course_id = intval($params['course_id']);
  58. } else {
  59. $this->course_id = $params['course_id'] = api_get_course_int_id();
  60. }
  61. //Setting course info
  62. if (isset($this->course_id)) {
  63. $this->course_info = api_get_course_info_by_id($this->course_id);
  64. }
  65. //Setting session id
  66. if (isset($params['session_id'])) {
  67. $this->session_id = intval($params['session_id']);
  68. } else {
  69. $this->session_id = $params['session_id'] = api_get_session_id();
  70. }
  71. //Setting user ids
  72. if (isset($params['user_id'])) {
  73. $this->user_id = intval($params['user_id']);
  74. } else {
  75. $this->user_id = $params['user_id'] = api_get_user_id();
  76. }
  77. //Setting user ids
  78. if (isset($params['exercise_id'])) {
  79. $this->exercise_id = intval($params['exercise_id']);
  80. } else {
  81. $this->exercise_id = 0;
  82. }
  83. //Setting user ids
  84. if (isset($params['question_id'])) {
  85. $this->question_id = intval($params['question_id']);
  86. } else {
  87. $this->question_id = 0;
  88. }
  89. $this->can_edit = false;
  90. if (api_is_allowed_to_edit()) {
  91. $this->can_edit = true;
  92. } else {
  93. if ($this->user_id == api_get_user_id()) {
  94. $this->can_edit = true;
  95. }
  96. }
  97. //Settings the params array
  98. $this->params = $params;
  99. $this->store_path = api_get_path(SYS_COURSE_PATH).$this->course_info['path'].'/exercises/';
  100. $this->create_user_folder();
  101. $this->store_path = $this->store_path.implode('/', array($this->session_id, $this->exercise_id, $this->question_id, $this->user_id)).'/';
  102. $this->filename = $this->generate_filename();
  103. $this->store_filename = $this->store_path.$this->filename;
  104. }
  105. /**
  106. * Generates the filename with the next format:
  107. * (course_id)/(session_id)/(user_id)/(exercise_id)/(question_id)/(exe_id)
  108. *
  109. * @return string
  110. */
  111. function generate_filename() {
  112. if (!empty($this->params)) {
  113. //filename
  114. //course_id/session_id/user_id/exercise_id/question_id/exe_id
  115. $filename_array = array($this->params['course_id'], $this->params['session_id'], $this->params['user_id'], $this->params['exercise_id'], $this->params['question_id'], $this->params['exe_id']);
  116. return implode('-', $filename_array);
  117. } else {
  118. return api_get_unique_id();
  119. }
  120. }
  121. /**
  122. * Delete audio file
  123. * @return number
  124. */
  125. function delete_files() {
  126. $delete_found = 0;
  127. if ($this->can_edit) {
  128. $file = $this->load_filename_if_exists();
  129. $path_info = pathinfo($file);
  130. foreach($this->available_extensions as $extension) {
  131. $file_to_delete = $path_info['dirname'].'/'.$path_info['filename'].'.'.$extension;
  132. if (is_file($file_to_delete)) {
  133. unlink($file_to_delete);
  134. $delete_found = 1;
  135. }
  136. }
  137. }
  138. return $delete_found;
  139. }
  140. /**
  141. *
  142. * Tricky stuff to deal with the feedback = 0 in exercises (all question per page)
  143. * @param unknown_type $exe_id
  144. */
  145. function replace_with_real_exe($exe_id) {
  146. $filename = null;
  147. //@ugly fix
  148. foreach($this->available_extensions as $extension) {
  149. $items = explode('-', $this->filename);
  150. $items[5] = 'temp_exe';
  151. $filename = implode('-', $items);
  152. if (is_file($this->store_path.$filename.'.'.$extension)) {
  153. $old_name = $this->store_path.$filename.'.'.$extension;
  154. $items = explode('-', $this->filename);
  155. $items[5] = $exe_id;
  156. $filename = $filename = implode('-', $items);
  157. $new_name = $this->store_path.$filename.'.'.$extension;
  158. //var_dump($old_name, $new_name);
  159. rename($old_name, $new_name);
  160. break;
  161. }
  162. }
  163. }
  164. function load_filename_if_exists($load_from_database = false) {
  165. $filename = null;
  166. //@ugly fix
  167. foreach($this->available_extensions as $extension) {
  168. if (is_file($this->store_path.$this->filename.'.'.$extension)) {
  169. $filename = $this->filename.'.'.$extension;
  170. break;
  171. }
  172. }
  173. //temp_exe
  174. if ($load_from_database) {
  175. //Load the real filename just if exists
  176. if (isset($this->params['exe_id']) && isset($this->params['user_id']) && isset($this->params['question_id']) && isset($this->params['session_id']) && isset($this->params['course_id'])) {
  177. $attempt_table = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
  178. $sql = "SELECT filename FROM $attempt_table
  179. WHERE exe_id = ".$this->params['exe_id']." AND
  180. user_id = ".$this->params['user_id']." AND
  181. question_id = ".$this->params['question_id']." AND
  182. session_id = ".$this->params['session_id']." AND
  183. course_code = '".$this->course_info['code']."' LIMIT 1";
  184. $result = Database::query($sql);
  185. $result = Database::fetch_row($result,'ASSOC');
  186. if (isset($result) && isset($result[0]) && !empty($result[0])) {
  187. $filename = $result[0];
  188. }
  189. }
  190. }
  191. if (is_file($this->store_path.$filename)) {
  192. return $this->store_path.$filename;
  193. }
  194. return null;
  195. }
  196. /**
  197. *
  198. * Get the URL of the file
  199. * path courses/XXX/exercises/(session_id)/(exercise_id)/(question_id)/(user_id)/
  200. *
  201. * @return string
  202. */
  203. function get_public_url($force_download = 0) {
  204. $params = $this->get_params(true);
  205. $url = api_get_path(WEB_AJAX_PATH).'nanogong.ajax.php?a=get_file&download='.$force_download.'&'.$params;
  206. $params = $this->get_params();
  207. $filename = basename($this->load_filename_if_exists());
  208. $url = api_get_path(WEB_COURSE_PATH).$this->course_info['code'].'/exercises/'.
  209. $params['session_id'].'/'.$params['exercise_id'].'/'.$params['question_id'].'/'.$params['user_id'].'/'.$filename;
  210. return $url;
  211. }
  212. /**
  213. * Uploads the nanogong wav file
  214. */
  215. public function upload_file($is_nano = false) {
  216. require_once api_get_path(LIBRARY_PATH).'fileDisplay.lib.php';
  217. require_once api_get_path(LIBRARY_PATH).'document.lib.php';
  218. require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
  219. if (!empty($_FILES)) {
  220. $upload_ok = process_uploaded_file($_FILES['file'], false);
  221. if (!is_uploaded_file($_FILES['file']['tmp_name'])) {
  222. return 0;
  223. }
  224. if ($upload_ok) {
  225. // Check if there is enough space to save the file
  226. if (!DocumentManager::enough_space($_FILES['file']['size'], DocumentManager::get_course_quota())) {
  227. return 0;
  228. }
  229. //first we delete everything before uploading the file
  230. $this->delete_files();
  231. //Reload the filename variable
  232. $file_name = add_ext_on_mime($_FILES['file']['name'], $_FILES['file']['type']);
  233. $file_name = strtolower($file_name);
  234. $file_info = pathinfo($file_name);
  235. if ($is_nano == true) {
  236. $file_info['extension'] = 'wav';
  237. }
  238. $file_name = $this->filename.'.'.$file_info['extension'];
  239. if (in_array($file_info['extension'], $this->available_extensions)) {
  240. if (move_uploaded_file($_FILES['file']['tmp_name'], $this->store_path.$file_name)) {
  241. $this->store_filename = $this->store_path.$file_name;
  242. //error_log('saved');
  243. return 1;
  244. }
  245. }
  246. }
  247. }
  248. return 0;
  249. }
  250. /**
  251. * Show the audio file + a button to download
  252. *
  253. */
  254. public function show_audio_file($show_delete_button = false) {
  255. $html = '&nbsp;&nbsp;';
  256. $file_path = $this->load_filename_if_exists();
  257. if (!empty($file_path)) {
  258. $url = $this->get_public_url(true);
  259. $actions = Display::url(Display::return_icon('save.png', get_lang('Download'), array(), ICON_SIZE_SMALL), $url, array('target'=>'_blank'));
  260. $download_button = Display::url(get_lang('Download'), $url, array('class' =>'btn'));
  261. if ($show_delete_button) {
  262. $actions .= ' '.Display::url(Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL), "#", array('onclick'=>'delete_file();'));
  263. }
  264. $basename = basename($file_path);
  265. $path_info = pathinfo($basename);
  266. if ($path_info['extension'] == 'wav') {
  267. $html .= '<script>
  268. $(document).ready( function() {
  269. var java_enabled = navigator.javaEnabled();
  270. if (java_enabled) {
  271. $("#nanogong_warning").hide();
  272. $("#nanogong_player_id").show();
  273. } else {
  274. $("#nanogong_warning").show();
  275. $("#nanogong_player_id").hide();
  276. }
  277. });
  278. </script>';
  279. $html .= '<div id="nanogong_player_id" class="nanogong_player_container">';
  280. $html .= '<div class="action_player">'.$actions.'</div>';
  281. $html .= '<div class="nanogong_player">';
  282. $html .= '<applet id="nanogong_player" archive="'.api_get_path(WEB_LIBRARY_PATH).'nanogong/nanogong.jar" code="gong.NanoGong" width="250" height="40" ALIGN="middle">';
  283. $html .= '<param name="ShowRecordButton" value="false" />'; // default true
  284. $html .= '<param name="ShowSaveButton" value="false" />'; //you can save in local computer | (default true)
  285. //echo '<param name="ShowSpeedButton" value="false" />'; // default true
  286. //echo '<param name="ShowAudioLevel" value="false" />'; // it displays the audiometer | (default true)
  287. $html .= '<param name="ShowTime" value="true" />'; // default false
  288. $html .= '<param name="Color" value="#FFFFFF" />';
  289. //echo '<param name="StartTime" value="10.5" />';
  290. //echo '<param name="EndTime" value="65" />';
  291. $html .= '<param name="AudioFormat" value="ImaADPCM" />';// ImaADPCM (more speed), Speex (more compression)|(default Speex)
  292. //$html .= '<param name="AudioFormat" value="Speex" />';// ImaADPCM (more speed), Speex (more compression)|(default Speex)
  293. //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)
  294. //echo '<param name="SamplingRate" value="32000" />';
  295. //echo '<param name="MaxDuration" value="60" />';
  296. $html .= '<param name="SoundFileURL" value="'.$url.'" />';//load a file |(default "")
  297. $html .= '</applet>';
  298. $html .= '</div>';
  299. $html .= '</div>';
  300. $html .= '<div id="nanogong_warning">'.Display::return_message(get_lang('BrowserNotSupportNanogongListen'),'warning').$download_button.'</div>';
  301. } elseif(in_array($path_info['extension'],array('mp3', 'ogg','wav'))) {
  302. $js_path = api_get_path(WEB_LIBRARY_PATH).'javascript/';
  303. $html .= '<link rel="stylesheet" href="'.$js_path.'jquery-jplayer/skins/blue/jplayer.blue.monday.css" type="text/css">';
  304. $html .= '<script type="text/javascript" src="'.$js_path.'jquery-jplayer/jquery.jplayer.min.js"></script>';
  305. $html .= '<div class="nanogong_player"></div>';
  306. $html .= '<br /><div class="action_player">'.$actions.'</div><br /><br /><br />';
  307. $jquery .= ' $("#audio_preview").jPlayer({
  308. ready: function() {
  309. $(this).jPlayer("setMedia", {
  310. '.$path_info['extension'].' : "'.$url.'"
  311. });
  312. },
  313. swfPath: "'.$js_path.'jquery-jplayer",
  314. supplied: "mp3, ogg, oga, wav",
  315. solution: "flash, html", // Do not change this setting otherwise
  316. width:0,
  317. height:0,
  318. });';
  319. $html .= '<script type="text/javascript">
  320. $(document).ready( function() {
  321. //Experimental changes to preview mp3, ogg files
  322. '.$jquery.'
  323. });
  324. </script>';
  325. //@todo fix this
  326. $html .= '
  327. <div id="audio_preview" class="jp-jplayer"></div>
  328. <div class="jp-audio audio_preview_container">
  329. <div class="jp-type-single">
  330. <div id="jp_interface_1" class="jp-interface">
  331. <ul class="jp-controls">
  332. <li><a href="#" class="jp-play" tabindex="1">play</a></li>
  333. <li><a href="#" class="jp-pause" tabindex="1">pause</a></li>
  334. <li><a href="#" class="jp-stop" tabindex="1">stop</a></li>
  335. <li><a href="#" class="jp-mute" tabindex="1">mute</a></li>
  336. <li><a href="#" class="jp-unmute" tabindex="1">unmute</a></li>
  337. </ul>
  338. <div class="jp-progress">
  339. <div class="jp-seek-bar">
  340. <div class="jp-play-bar"></div>
  341. </div>
  342. </div>
  343. <div class="jp-volume-bar">
  344. <div class="jp-volume-bar-value"></div>
  345. </div>
  346. <div class="jp-current-time"></div>
  347. <div class="jp-duration"></div>
  348. </div>
  349. <div id="jp_playlist_1" class="jp-playlist">
  350. </div>
  351. </div>
  352. </div>
  353. <br />';
  354. }
  355. return $html;
  356. }
  357. }
  358. /*
  359. var filename = document.getElementById("audio_title").value+".wav";
  360. var filename = filename.replace(/\s/g, "_");//replace spaces by _
  361. var filename = encodeURIComponent(filename);
  362. var filepath="'.urlencode($filepath).'";
  363. var dir="'.urlencode($dir).'";
  364. var course_code="'.urlencode($course_code).'";
  365. var urlnanogong="'.$url.'?filename="+filename+"&filepath="+filepath+"&dir="+dir+"&course_code="+course_code;
  366. */
  367. /**
  368. * Returns the nanogong javascript code
  369. * @return string
  370. */
  371. function return_js() {
  372. $params = $this->get_params(true);
  373. $url = api_get_path(WEB_AJAX_PATH).'nanogong.ajax.php?a=save_file&'.$params.'&is_nano=1';
  374. $url_load_file = api_get_path(WEB_AJAX_PATH).'nanogong.ajax.php?a=show_audio&'.$params;
  375. $url_delete = api_get_path(WEB_AJAX_PATH).'nanogong.ajax.php?a=delete&'.$params;
  376. $js = '<script language="javascript">
  377. //lang vars
  378. var lang_no_applet = "'.get_lang('NanogongNoApplet').'";
  379. var lang_record_before_save = "'.get_lang('NanogongRecordBeforeSave').'";
  380. var lang_give_a_title = "'.get_lang('NanogongGiveTitle').'";
  381. var lang_failed_to_submit = "'.get_lang('NanogongFailledToSubmit').'";
  382. var lang_submitted = "'.get_lang('NanogongSubmitted').'";
  383. var lang_deleted = "'.get_lang('Deleted').'";
  384. var is_nano = 0;
  385. function check_gong() {
  386. //var record = document.getElementById("nanogong");
  387. var recorder;
  388. var java_enabled = navigator.javaEnabled()
  389. return java_enabled;
  390. }
  391. $(document).ready( function() {
  392. $("#no_nanogong_div").hide();
  393. $("#nanogong_div").hide();
  394. var check_js = check_gong();
  395. if (check_js == true) {
  396. $("#nanogong_div").show();
  397. $("#no_nanogong_div").hide();
  398. is_nano = 1;
  399. $(".nanogong_player").show();
  400. } else {
  401. $("#no_nanogong_div").show();
  402. $("#nanogong_div").hide();
  403. $(".nanogong_player").hide();
  404. }
  405. //show always the mp3/ogg upload form (for dev purposes)
  406. //$("#no_nanogong_div").show();
  407. //$("#nanogong_div").hide();
  408. });
  409. function delete_file() {
  410. $.ajax({
  411. url: "'.$url_delete.'",
  412. success:function(data) {
  413. $("#status_warning").hide();
  414. $("#status_ok").hide();
  415. $("#messages").html(data);
  416. $("#messages").show();
  417. $("#preview").hide();
  418. }
  419. });
  420. }
  421. function upload_file() {
  422. $("#form_nanogong_simple").submit();
  423. }
  424. function send_voice() {
  425. $("#status_warning").hide();
  426. $("#status_ok").hide();
  427. $("#messages").hide();
  428. var check_js = check_gong();
  429. //check
  430. if (!check_js) {
  431. $("#status_warning").html(lang_no_applet);
  432. $("#status_warning").show();
  433. return false;
  434. }
  435. var recorder = document.getElementById("nanogong");
  436. if (!recorder || !check_js) {
  437. //alert(lang_no_applet)
  438. $("#status_warning").html(lang_no_applet);
  439. $("#status_warning").show();
  440. return false;
  441. }
  442. var duration = parseInt(recorder.sendGongRequest("GetMediaDuration", "audio")) || 0;
  443. if (duration <= 0) {
  444. $("#status_warning").html(lang_record_before_save);
  445. $("#status_warning").show();
  446. return false;
  447. }
  448. var applet = document.getElementById("nanogong");
  449. var ret = applet.sendGongRequest("PostToForm", "'.$url.'", "file", "", "temp"); // PostToForm, postURL, inputname, cookie, filename
  450. if (ret == 1) {
  451. $("#status_ok").html(lang_submitted);
  452. $("#status_ok").show();
  453. $.ajax({
  454. url:"'.$url_load_file.'&is_nano="+is_nano,
  455. success: function(data){
  456. $("#preview").html(data);
  457. $("#preview").show();
  458. }
  459. });
  460. } else {
  461. //alert(lang_submitted+"\n"+ret);
  462. $("#status_warning").html(lang_failed_to_submit);
  463. $("#status_warning").show();
  464. }
  465. return false;
  466. }
  467. </script>';
  468. return $js;
  469. }
  470. /**
  471. * Returns the HTML form to upload a nano file or upload a file
  472. */
  473. function return_form($message = null) {
  474. $params = $this->get_params(true);
  475. $url = api_get_path(WEB_AJAX_PATH).'nanogong.ajax.php?a=save_file&'.$params;
  476. //check browser support and load form
  477. $array_browser = api_browser_support('check_browser');
  478. $preview_file = $this->show_audio_file(true, true);
  479. $preview_file = Display::div($preview_file, array('id' => 'preview', 'style' => 'text-align:center;'));
  480. $html .= '<center>';
  481. //Use normal upload file
  482. $html .= Display::return_icon('microphone.png', get_lang('PressRecordButton'),'','128');
  483. $html .='<br />';
  484. $html .= '<div id="no_nanogong_div">';
  485. $html .= Display::return_message(get_lang('BrowserNotSupportNanogongSend'), 'warning');
  486. $html .= '<form id="form_nanogong_simple" action="'.$url.'" name="form_nanogong" method="POST" enctype="multipart/form-data">';
  487. $html .= '<input type="file" name="file">';
  488. $html .= '<a href="#" class="btn" onclick="upload_file()" />'.get_lang('UploadFile').'</a>';
  489. $html .= '</form></div>';
  490. $html .= '<div id="nanogong_div">';
  491. $html .= '<applet id="nanogong" archive="'.api_get_path(WEB_LIBRARY_PATH).'nanogong/nanogong.jar" code="gong.NanoGong" width="250" height="40" align="middle">';
  492. //echo '<param name="ShowRecordButton" value="false" />'; // default true
  493. // echo '<param name="ShowSaveButton" value="false" />'; //you can save in local computer | (default true)
  494. //echo '<param name="ShowSpeedButton" value="false" />'; // default true
  495. //echo '<param name="ShowAudioLevel" value="false" />'; // it displays the audiometer | (default true)
  496. $html .= '<param name="ShowTime" value="true" />'; // default false
  497. $html .= '<param name="Color" value="#FFFFFF" />'; // default #FFFFFF
  498. //echo '<param name="StartTime" value="10.5" />';
  499. //echo '<param name="EndTime" value="65" />';
  500. $html .= '<param name="AudioFormat" value="ImaADPCM" />';// ImaADPCM (more speed), Speex (more compression)|(default Speex)
  501. //$html .= '<param name="AudioFormat" value="Speex" />';// ImaADPCM (more speed), Speex (more compression)|(default Speex)
  502. //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)
  503. //echo '<param name="MaxDuration" value="60" />';
  504. //echo '<param name="SoundFileURL" value="http://somewhere.com/mysoundfile.wav" />';//load a file |(default "")
  505. $html .= '</applet>';
  506. $html .= '<br /><br /><br /><form name="form_nanogong_advanced">';
  507. $html .= '<input type="hidden" name="is_nano" value="1">';
  508. $html .= '<a href="#" class="btn" onclick="send_voice()" />'.get_lang('SendRecord').'</a>';
  509. $html .= '</form></div>';
  510. $html .= '</center>';
  511. $html .= '<div style="display:none" id="status_ok" class="confirmation-message"></div><div style="display:none" id="status_warning" class="warning-message"></div>';
  512. $html .= '<div id="messages">'.$message.'</div>';
  513. $html .= $preview_file;
  514. return $html;
  515. }
  516. function get_params($return_as_query = false) {
  517. if (empty($this->params)) {
  518. return false;
  519. }
  520. if ($return_as_query) {
  521. return http_build_query($this->params);
  522. }
  523. return $this->params;
  524. }
  525. function get_param_value($attribute) {
  526. if (isset($this->params[$attribute])) {
  527. return $this->params[$attribute];
  528. }
  529. }
  530. /**
  531. * Show a button to load the form
  532. * @return string
  533. */
  534. function show_button() {
  535. $params_string = $this->get_params(true);
  536. $html .= '<br />'.Display::url(get_lang('RecordAnswer'),api_get_path(WEB_AJAX_PATH).'nanogong.ajax.php?a=show_form&'.$params_string.'&TB_iframe=true&height=350&width=500',
  537. array('class'=>'btn thickbox'));
  538. $html .= '<br /><br />'.Display::return_message(get_lang('UseTheMessageBelowToAddSomeComments'));
  539. return $html;
  540. }
  541. }