nanogong.lib.php 22 KB

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