nanogong.lib.php 24 KB

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