nanogong.lib.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695
  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. public $filename;
  18. public $store_filename;
  19. public $store_path;
  20. public $params;
  21. public $can_edit = false;
  22. /* Files allowed to upload */
  23. public $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 int
  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 int $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. rename($old_name, $new_name);
  182. break;
  183. }
  184. }
  185. }
  186. /**
  187. * @param bool $load_from_database
  188. * @return null|string
  189. */
  190. function load_filename_if_exists($load_from_database = false)
  191. {
  192. $filename = null;
  193. //@ugly fix
  194. foreach ($this->available_extensions as $extension) {
  195. if (is_file($this->store_path.$this->filename.'.'.$extension)) {
  196. $filename = $this->filename.'.'.$extension;
  197. break;
  198. }
  199. }
  200. //temp_exe
  201. if ($load_from_database) {
  202. //Load the real filename just if exists
  203. if (isset($this->params['exe_id']) && isset($this->params['user_id']) &&
  204. isset($this->params['question_id']) && isset($this->params['session_id']) && isset($this->params['course_id'])) {
  205. $attempt_table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
  206. $sql = "SELECT filename FROM $attempt_table
  207. WHERE exe_id = ".$this->params['exe_id']." AND
  208. user_id = ".$this->params['user_id']." AND
  209. question_id = ".$this->params['question_id']." AND
  210. session_id = ".$this->params['session_id']." AND
  211. c_id = '".$this->course_info['real_id']."' LIMIT 1";
  212. $result = Database::query($sql);
  213. $result = Database::fetch_row($result, 'ASSOC');
  214. if (isset($result) && isset($result[0]) && !empty($result[0])) {
  215. $filename = $result[0];
  216. }
  217. }
  218. }
  219. if (is_file($this->store_path.$filename)) {
  220. return $this->store_path.$filename;
  221. }
  222. return null;
  223. }
  224. /**
  225. *
  226. * Get the URL of the file
  227. * path courses/XXX/exercises/(session_id)/(exercise_id)/(question_id)/(user_id)/
  228. * @param int $force_download
  229. *
  230. * @return string
  231. */
  232. function get_public_url($force_download = 0)
  233. {
  234. $params = $this->get_params(true);
  235. $url = api_get_path(WEB_AJAX_PATH).'nanogong.ajax.php?a=get_file&download='.$force_download.'&'.$params;
  236. $params = $this->get_params();
  237. $filename = basename($this->load_filename_if_exists());
  238. $url = api_get_path(WEB_COURSE_PATH).$this->course_info['path'].'/exercises/'.$params['session_id'].'/'.$params['exercise_id'].'/'.$params['question_id'].'/'.$params['user_id'].'/'.$filename;
  239. return $url;
  240. }
  241. /**
  242. * Uploads the nanogong wav file
  243. * @param bool
  244. */
  245. public function upload_file($is_nano = false)
  246. {
  247. if (!empty($_FILES)) {
  248. $upload_ok = FileManager::process_uploaded_file($_FILES['file'], false);
  249. if (!is_uploaded_file($_FILES['file']['tmp_name'])) {
  250. return 0;
  251. }
  252. if ($upload_ok) {
  253. // Check if there is enough space to save the file
  254. if (!DocumentManager::enough_space($_FILES['file']['size'], DocumentManager::get_course_quota())) {
  255. return 0;
  256. }
  257. //first we delete everything before uploading the file
  258. $this->delete_files();
  259. //Reload the filename variable
  260. $file_name = FileManager::add_ext_on_mime($_FILES['file']['name'], $_FILES['file']['type']);
  261. $file_name = strtolower($file_name);
  262. $file_info = pathinfo($file_name);
  263. if ($is_nano == true) {
  264. $file_info['extension'] = 'wav';
  265. }
  266. $file_name = $this->filename.'.'.$file_info['extension'];
  267. if (in_array($file_info['extension'], $this->available_extensions)) {
  268. if (move_uploaded_file($_FILES['file']['tmp_name'], $this->store_path.$file_name)) {
  269. $this->store_filename = $this->store_path.$file_name;
  270. return 1;
  271. }
  272. }
  273. }
  274. }
  275. return 0;
  276. }
  277. /**
  278. * Show the audio file + a button to download
  279. * @param bool
  280. */
  281. public function show_audio_file($show_delete_button = false)
  282. {
  283. $html = '';
  284. $file_path = $this->load_filename_if_exists();
  285. if (!empty($file_path)) {
  286. $url = $this->get_public_url(true);
  287. $actions = Display::url(
  288. Display::return_icon('save.png', get_lang('Download'), array(), ICON_SIZE_SMALL),
  289. $url,
  290. array('target' => '_blank')
  291. );
  292. $download_button = Display::url(get_lang('Download'), $url, array('class' => 'btn'));
  293. if ($show_delete_button) {
  294. $actions .= ' '.Display::url(
  295. Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL),
  296. "#",
  297. array('onclick' => 'delete_file();')
  298. );
  299. }
  300. $basename = basename($file_path);
  301. $path_info = pathinfo($basename);
  302. if ($path_info['extension'] == 'wav') {
  303. $html .= '<script>
  304. $(document).ready( function() {
  305. var java_enabled = navigator.javaEnabled();
  306. if (java_enabled) {
  307. $("#nanogong_warning").hide();
  308. $("#nanogong_player_id").show();
  309. } else {
  310. $("#nanogong_warning").show();
  311. $("#nanogong_player_id").hide();
  312. }
  313. });
  314. </script>';
  315. $html .= '<div id="nanogong_player_id" class="nanogong_player_container">';
  316. $html .= '<div class="action_player">'.$actions.'</div>';
  317. $html .= '<div class="nanogong_player">';
  318. $html .= '<applet id="nanogong_player" archive="'.api_get_path(
  319. WEB_LIBRARY_PATH
  320. ).'nanogong/nanogong.jar" code="gong.NanoGong" width="250" height="40" ALIGN="middle">';
  321. $html .= '<param name="ShowRecordButton" value="false" />'; // default true
  322. $html .= '<param name="ShowSaveButton" value="false" />'; //you can save in local computer | (default true)
  323. //echo '<param name="ShowSpeedButton" value="false" />'; // default true
  324. //echo '<param name="ShowAudioLevel" value="false" />'; // it displays the audiometer | (default true)
  325. $html .= '<param name="ShowTime" value="true" />'; // default false
  326. $html .= '<param name="Color" value="#FFFFFF" />';
  327. //echo '<param name="StartTime" value="10.5" />';
  328. //echo '<param name="EndTime" value="65" />';
  329. $html .= '<param name="AudioFormat" value="ImaADPCM" />'; // ImaADPCM (more speed), Speex (more compression)|(default Speex)
  330. //$html .= '<param name="AudioFormat" value="Speex" />';// ImaADPCM (more speed), Speex (more compression)|(default Speex)
  331. //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)
  332. //echo '<param name="SamplingRate" value="32000" />';
  333. //echo '<param name="MaxDuration" value="60" />';
  334. $html .= '<param name="SoundFileURL" value="'.$url.'" />'; //load a file |(default "")
  335. $html .= '</applet>';
  336. $html .= '</div>';
  337. $html .= '</div>';
  338. $html .= '<div id="nanogong_warning">'.Display::return_message(
  339. get_lang('BrowserDoesNotSupportNanogongPlayer'),
  340. 'warning'
  341. ).$download_button.'</div>';
  342. } elseif (in_array($path_info['extension'], array('mp3', 'ogg', 'wav'))) {
  343. $js_path = api_get_path(WEB_LIBRARY_PATH).'javascript/';
  344. $html .= '<link rel="stylesheet" href="'.$js_path.'jquery-jplayer/skins/blue/jplayer.blue.monday.css" type="text/css">';
  345. //$html .= '<link rel="stylesheet" href="' . $js_path . 'jquery-jplayer/skins/chamilo/jplayer.blue.monday.css" type="text/css">';
  346. $html .= '<script type="text/javascript" src="'.$js_path.'jquery-jplayer/jquery.jplayer.min.js"></script>';
  347. $html .= '<div class="nanogong_player"></div>';
  348. $html .= '<br /><div class="action_player">'.$actions.'</div><br /><br /><br />';
  349. $params = array(
  350. 'url' => $url,
  351. 'extension' => $path_info['extension'],
  352. 'count' => 1
  353. );
  354. $jquery = DocumentManager::generate_jplayer_jquery($params);
  355. $html .= '<script>
  356. $(document).ready( function() {
  357. //Experimental changes to preview mp3, ogg files
  358. '.$jquery.'
  359. });
  360. </script>';
  361. $html .= DocumentManager::generate_media_preview(1, 'advanced');
  362. }
  363. }
  364. return $html;
  365. }
  366. /*
  367. var filename = document.getElementById("audio_title").value+".wav";
  368. var filename = filename.replace(/\s/g, "_");//replace spaces by _
  369. var filename = encodeURIComponent(filename);
  370. var filepath="'.urlencode($filepath).'";
  371. var dir="'.urlencode($dir).'";
  372. var course_code="'.urlencode($course_code).'";
  373. var urlnanogong="'.$url.'?filename="+filename+"&filepath="+filepath+"&dir="+dir+"&course_code="+course_code;
  374. */
  375. /**
  376. * Returns the nanogong javascript code
  377. * @return string
  378. */
  379. function return_js()
  380. {
  381. $params = $this->get_params(true);
  382. $url = api_get_path(WEB_AJAX_PATH).'nanogong.ajax.php?a=save_file&'.$params.'&is_nano=1';
  383. $url_load_file = api_get_path(WEB_AJAX_PATH).'nanogong.ajax.php?a=show_audio&'.$params;
  384. $url_delete = api_get_path(WEB_AJAX_PATH).'nanogong.ajax.php?a=delete&'.$params;
  385. $js = '<script language="javascript">
  386. //lang vars
  387. var lang_no_applet = "'.get_lang('NanogongNoApplet').'";
  388. var lang_record_before_save = "'.get_lang('NanogongRecordBeforeSave').'";
  389. var lang_give_a_title = "'.get_lang('NanogongGiveTitle').'";
  390. var lang_failed_to_submit = "'.get_lang('NanogongFailledToSubmit').'";
  391. var lang_submitted = "'.get_lang('NanogongSubmitted').'";
  392. var lang_deleted = "'.get_lang('Deleted').'";
  393. var is_nano = 0;
  394. function check_gong() {
  395. //var record = document.getElementById("nanogong");
  396. var recorder;
  397. var java_enabled = navigator.javaEnabled()
  398. return java_enabled;
  399. }
  400. function show_simple_upload_form() {
  401. $("#no_nanogong_div").show();
  402. //$("#nanogong_div").hide();
  403. $("#preview").hide();
  404. }
  405. $(document).ready( function() {
  406. $("#no_nanogong_div").hide();
  407. $("#nanogong_div").hide();
  408. var check_js = check_gong();
  409. if (check_js == true) {
  410. $("#nanogong_div").show();
  411. $("#no_nanogong_div").hide();
  412. is_nano = 1;
  413. $(".nanogong_player").show();
  414. } else {
  415. $("#no_nanogong_div").show();
  416. $("#nanogong_div").hide();
  417. $(".nanogong_player").hide();
  418. }
  419. //show always the mp3/ogg upload form (for dev purposes)
  420. //$("#no_nanogong_div").show();
  421. //$("#nanogong_div").hide();
  422. });
  423. function delete_file() {
  424. $.ajax({
  425. url: "'.$url_delete.'",
  426. success:function(data) {
  427. $("#status_warning").hide();
  428. $("#status_ok").hide();
  429. $("#messages").html(data);
  430. $("#messages").show();
  431. $("#preview").hide();
  432. }
  433. });
  434. }
  435. function upload_file() {
  436. $("#form_nanogong_simple").submit();
  437. }
  438. function send_voice() {
  439. $("#status_warning").hide();
  440. $("#status_ok").hide();
  441. $("#messages").hide();
  442. var check_js = check_gong();
  443. var recorder = document.getElementById("nanogong");
  444. if (!recorder || !check_js) {
  445. //alert(lang_no_applet)
  446. $("#status_warning").html(lang_no_applet);
  447. $("#status_warning").show();
  448. //Show form
  449. $("#no_nanogong_div").show();
  450. $("#nanogong_div").hide();
  451. return false;
  452. }
  453. var duration = parseInt(recorder.sendGongRequest("GetMediaDuration", "audio")) || 0;
  454. if (duration <= 0) {
  455. $("#status_warning").html(lang_record_before_save);
  456. $("#status_warning").show();
  457. return false;
  458. }
  459. var applet = document.getElementById("nanogong");
  460. var ret = applet.sendGongRequest("PostToForm", "'.$url.'", "file", "", "temp"); // PostToForm, postURL, inputname, cookie, filename
  461. if (ret == 1) {
  462. $("#status_ok").html(lang_submitted);
  463. $("#status_ok").show();
  464. $.ajax({
  465. url:"'.$url_load_file.'&is_nano="+is_nano,
  466. success: function(data){
  467. $("#preview").html(data);
  468. $("#preview").show();
  469. }
  470. });
  471. } else {
  472. //alert(lang_submitted+"\n"+ret);
  473. $("#status_warning").html(lang_failed_to_submit);
  474. $("#status_warning").show();
  475. }
  476. return false;
  477. }
  478. </script>';
  479. return $js;
  480. }
  481. /**
  482. * Returns the HTML form to upload a nano file or upload a file
  483. * @param string
  484. */
  485. function return_form($message = null)
  486. {
  487. $params = $this->get_params(true);
  488. $url = api_get_path(WEB_AJAX_PATH).'nanogong.ajax.php?a=save_file&'.$params;
  489. //check browser support and load form
  490. $array_browser = api_browser_support('check_browser');
  491. $preview_file = $this->show_audio_file(true, true);
  492. $preview_file = Display::div(
  493. $preview_file,
  494. array('id' => 'preview', 'style' => 'text-align:center; padding-left: 25px;')
  495. );
  496. $html = '<center>';
  497. //Use normal upload file
  498. $html .= Display::return_icon('microphone.png', get_lang('PressRecordButton'), '', ICON_SIZE_BIG);
  499. $html .= '<br />';
  500. $html .= '<div id="nanogong_div">';
  501. $html .= '<applet id="nanogong" archive="'.api_get_path(
  502. WEB_LIBRARY_PATH
  503. ).'nanogong/nanogong.jar" code="gong.NanoGong" width="250" height="40" align="middle">';
  504. //echo '<param name="ShowRecordButton" value="false" />'; // default true
  505. // echo '<param name="ShowSaveButton" value="false" />'; //you can save in local computer | (default true)
  506. //echo '<param name="ShowSpeedButton" value="false" />'; // default true
  507. //echo '<param name="ShowAudioLevel" value="false" />'; // it displays the audiometer | (default true)
  508. $html .= '<param name="ShowTime" value="true" />'; // default false
  509. $html .= '<param name="Color" value="#FFFFFF" />'; // default #FFFFFF
  510. //echo '<param name="StartTime" value="10.5" />';
  511. //echo '<param name="EndTime" value="65" />';
  512. $html .= '<param name="AudioFormat" value="ImaADPCM" />'; // ImaADPCM (more speed), Speex (more compression)|(default Speex)
  513. //$html .= '<param name="AudioFormat" value="Speex" />';// ImaADPCM (more speed), Speex (more compression)|(default Speex)
  514. //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)
  515. //echo '<param name="MaxDuration" value="60" />';
  516. //echo '<param name="SoundFileURL" value="http://somewhere.com/mysoundfile.wav" />';//load a file |(default "")
  517. $html .= '</applet>';
  518. $html .= '<br /><br /><br />';
  519. $html .= '<form name="form_nanogong_advanced">';
  520. $html .= '<input type="hidden" name="is_nano" value="1">';
  521. $html .= '<a href="#" class="btn" onclick="send_voice()" />'.get_lang('SendRecord').'</a>';
  522. $html .= '</form></div>';
  523. $html .= Display::url(
  524. get_lang('ProblemsRecordingUploadYourOwnAudioFile'),
  525. 'javascript:void(0)',
  526. array('onclick' => 'show_simple_upload_form();')
  527. );
  528. $html .= '<br /><br /><div id="no_nanogong_div">';
  529. //$html .= Display::return_message(get_lang('BrowserNotSupportNanogongSend'), 'warning');
  530. $html .= '<form id="form_nanogong_simple" class="form-search" action="'.$url.'" name="form_nanogong" method="POST" enctype="multipart/form-data">';
  531. $html .= '<input type="file" name="file">';
  532. $html .= '<a href="#" class="btn" onclick="upload_file()" />'.get_lang('UploadFile').'</a>';
  533. $html .= '</form>';
  534. $html .= '</div>';
  535. $html .= '</center>';
  536. $html .= '<div style="display:none" id="status_ok" class="confirmation-message"></div><div style="display:none" id="status_warning" class="warning-message"></div>';
  537. $html .= '<div id="messages">'.$message.'</div>';
  538. $html .= $preview_file;
  539. return $html;
  540. }
  541. /**
  542. * @param bool $return_as_query
  543. * @return bool|string
  544. */
  545. function get_params($return_as_query = false)
  546. {
  547. if (empty($this->params)) {
  548. return false;
  549. }
  550. if ($return_as_query) {
  551. return http_build_query($this->params);
  552. }
  553. return $this->params;
  554. }
  555. /**
  556. * @param $attribute
  557. * @return mixed
  558. */
  559. function get_param_value($attribute)
  560. {
  561. if (isset($this->params[$attribute])) {
  562. return $this->params[$attribute];
  563. }
  564. }
  565. /**
  566. * Show a button to load the form
  567. * @return string
  568. */
  569. function show_button()
  570. {
  571. $params_string = $this->get_params(true);
  572. $html = '<br />'.Display::url(
  573. get_lang('RecordAnswer'),
  574. api_get_path(
  575. WEB_AJAX_PATH
  576. ).'nanogong.ajax.php?a=show_form&'.$params_string.'&TB_iframe=true&height=400&width=500',
  577. array('class' => 'btn thickbox')
  578. );
  579. $html .= '<br /><br />'.Display::return_message(get_lang('UseTheMessageBelowToAddSomeComments'));
  580. return $html;
  581. }
  582. }