nanogong.lib.php 24 KB

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