nanogong.lib.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675
  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).'fileDisplay.lib.php';
  252. require_once api_get_path(LIBRARY_PATH).'document.lib.php';
  253. require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
  254. if (!empty($_FILES)) {
  255. $upload_ok = process_uploaded_file($_FILES['file'], false);
  256. if (!is_uploaded_file($_FILES['file']['tmp_name'])) {
  257. return 0;
  258. }
  259. if ($upload_ok) {
  260. // Check if there is enough space to save the file
  261. if (!DocumentManager::enough_space($_FILES['file']['size'], DocumentManager::get_course_quota())) {
  262. return 0;
  263. }
  264. //first we delete everything before uploading the file
  265. $this->delete_files();
  266. //Reload the filename variable
  267. $file_name = add_ext_on_mime($_FILES['file']['name'], $_FILES['file']['type']);
  268. $file_name = strtolower($file_name);
  269. $file_info = pathinfo($file_name);
  270. if ($is_nano == true) {
  271. $file_info['extension'] = 'wav';
  272. }
  273. $file_name = $this->filename.'.'.$file_info['extension'];
  274. if (in_array($file_info['extension'], $this->available_extensions)) {
  275. if (move_uploaded_file($_FILES['file']['tmp_name'], $this->store_path.$file_name)) {
  276. $this->store_filename = $this->store_path.$file_name;
  277. return 1;
  278. }
  279. }
  280. }
  281. }
  282. return 0;
  283. }
  284. /**
  285. * Show the audio file + a button to download
  286. * @param bool
  287. */
  288. public function show_audio_file($show_delete_button = false)
  289. {
  290. $html = '';
  291. $file_path = $this->load_filename_if_exists();
  292. if (!empty($file_path)) {
  293. $url = $this->get_public_url(true);
  294. $actions = Display::url(Display::return_icon('save.png', get_lang('Download'), array(), ICON_SIZE_SMALL), $url, array('target'=>'_blank'));
  295. $download_button = Display::url(get_lang('Download'), $url, array('class' =>'btn'));
  296. if ($show_delete_button) {
  297. $actions .= ' '.Display::url(Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL), "#", array('onclick'=>'delete_file();'));
  298. }
  299. $basename = basename($file_path);
  300. $path_info = pathinfo($basename);
  301. if ($path_info['extension'] == 'wav') {
  302. $html .= '<script>
  303. $(document).ready( function() {
  304. var java_enabled = navigator.javaEnabled();
  305. if (java_enabled) {
  306. $("#nanogong_warning").hide();
  307. $("#nanogong_player_id").show();
  308. } else {
  309. $("#nanogong_warning").show();
  310. $("#nanogong_player_id").hide();
  311. }
  312. });
  313. </script>';
  314. $html .= '<div id="nanogong_player_id" class="nanogong_player_container">';
  315. $html .= '<div class="action_player">'.$actions.'</div>';
  316. $html .= '<div class="nanogong_player">';
  317. $html .= '<applet id="nanogong_player" archive="'.api_get_path(WEB_LIBRARY_PATH).'nanogong/nanogong.jar" code="gong.NanoGong" width="250" height="95" 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="ShowAudioLevel" value="false" />'; // it displays the audiometer | (default true)
  321. $html .= '<param name="ShowTime" value="true" />'; // default false
  322. $html .= '<param name="Color" value="#FFFFFF" />';
  323. $html .= '<param name="ShowSpeedButton" value="false" />';
  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(get_lang('BrowserDoesNotSupportNanogongPlayer'), 'warning').$download_button.'</div>';
  336. } elseif(in_array($path_info['extension'],array('mp3', 'ogg','wav'))) {
  337. $js_path = api_get_path(WEB_LIBRARY_PATH).'javascript/';
  338. $html .= '<link rel="stylesheet" href="'.$js_path.'jquery-jplayer/skins/blue/jplayer.blue.monday.css" type="text/css">';
  339. //$html .= '<link rel="stylesheet" href="' . $js_path . 'jquery-jplayer/skins/chamilo/jplayer.blue.monday.css" type="text/css">';
  340. $html .= '<script type="text/javascript" src="'.$js_path.'jquery-jplayer/jquery.jplayer.min.js"></script>';
  341. $html .= '<div class="nanogong_player"></div>';
  342. $html .= '<br /><div class="action_player">'.$actions.'</div><br /><br /><br />';
  343. $params = array(
  344. 'url' => $url,
  345. 'extension' =>$path_info['extension'],
  346. 'count'=> 1
  347. );
  348. $jquery = DocumentManager::generate_jplayer_jquery($params);
  349. $html .= '<script>
  350. $(document).ready( function() {
  351. //Experimental changes to preview mp3, ogg files
  352. '.$jquery.'
  353. });
  354. </script>';
  355. $html .= DocumentManager::generate_media_preview(1, 'advanced');
  356. }
  357. }
  358. return $html;
  359. }
  360. /*
  361. var filename = document.getElementById("audio_title").value+".wav";
  362. var filename = filename.replace(/\s/g, "_");//replace spaces by _
  363. var filename = encodeURIComponent(filename);
  364. var filepath="'.urlencode($filepath).'";
  365. var dir="'.urlencode($dir).'";
  366. var course_code="'.urlencode($course_code).'";
  367. var urlnanogong="'.$url.'?filename="+filename+"&filepath="+filepath+"&dir="+dir+"&course_code="+course_code;
  368. */
  369. /**
  370. * Returns the nanogong javascript code
  371. * @return string
  372. */
  373. public function return_js()
  374. {
  375. $params = $this->get_params(true);
  376. $url = api_get_path(WEB_AJAX_PATH).'nanogong.ajax.php?a=save_file&'.$params.'&is_nano=1';
  377. $url_load_file = api_get_path(WEB_AJAX_PATH).'nanogong.ajax.php?a=show_audio&'.$params;
  378. $url_delete = api_get_path(WEB_AJAX_PATH).'nanogong.ajax.php?a=delete&'.$params;
  379. $js = '<script language="javascript">
  380. //lang vars
  381. var lang_no_applet = "'.get_lang('NanogongNoApplet').'";
  382. var lang_record_before_save = "'.get_lang('NanogongRecordBeforeSave').'";
  383. var lang_give_a_title = "'.get_lang('NanogongGiveTitle').'";
  384. var lang_failed_to_submit = "'.get_lang('NanogongFailledToSubmit').'";
  385. var lang_submitted = "'.get_lang('NanogongSubmitted').'";
  386. var lang_deleted = "'.get_lang('Deleted').'";
  387. var is_nano = 0;
  388. function check_gong() {
  389. //var record = document.getElementById("nanogong");
  390. var recorder;
  391. var java_enabled = navigator.javaEnabled()
  392. return java_enabled;
  393. }
  394. function show_simple_upload_form() {
  395. $("#no_nanogong_div").show();
  396. //$("#nanogong_div").hide();
  397. $("#preview").hide();
  398. }
  399. $(document).ready( function() {
  400. $("#no_nanogong_div").hide();
  401. $("#nanogong_div").hide();
  402. var check_js = check_gong();
  403. if (check_js == true) {
  404. $("#nanogong_div").show();
  405. $("#no_nanogong_div").hide();
  406. is_nano = 1;
  407. $(".nanogong_player").show();
  408. } else {
  409. $("#no_nanogong_div").show();
  410. $("#nanogong_div").hide();
  411. $(".nanogong_player").hide();
  412. }
  413. //show always the mp3/ogg upload form (for dev purposes)
  414. //$("#no_nanogong_div").show();
  415. //$("#nanogong_div").hide();
  416. });
  417. function delete_file() {
  418. $.ajax({
  419. url: "'.$url_delete.'",
  420. success:function(data) {
  421. $("#status_warning").hide();
  422. $("#status_ok").hide();
  423. $("#messages").html(data);
  424. $("#messages").show();
  425. $("#preview").hide();
  426. }
  427. });
  428. }
  429. function upload_file() {
  430. $("#form_nanogong_simple").submit();
  431. }
  432. function send_voice() {
  433. $("#status_warning").hide();
  434. $("#status_ok").hide();
  435. $("#messages").hide();
  436. var check_js = check_gong();
  437. var recorder = document.getElementById("nanogong");
  438. if (!recorder || !check_js) {
  439. //alert(lang_no_applet)
  440. $("#status_warning").html(lang_no_applet);
  441. $("#status_warning").show();
  442. //Show form
  443. $("#no_nanogong_div").show();
  444. $("#nanogong_div").hide();
  445. return false;
  446. }
  447. var duration = parseInt(recorder.sendGongRequest("GetMediaDuration", "audio")) || 0;
  448. if (duration <= 0) {
  449. $("#status_warning").html(lang_record_before_save);
  450. $("#status_warning").show();
  451. return false;
  452. }
  453. var applet = document.getElementById("nanogong");
  454. var ret = applet.sendGongRequest("PostToForm", "'.$url.'", "file", "", "temp"); // PostToForm, postURL, inputname, cookie, filename
  455. if (ret == 1) {
  456. $("#status_ok").html(lang_submitted);
  457. $("#status_ok").show();
  458. $.ajax({
  459. url:"'.$url_load_file.'&is_nano="+is_nano,
  460. success: function(data){
  461. $("#preview").html(data);
  462. $("#preview").show();
  463. }
  464. });
  465. } else {
  466. //alert(lang_submitted+"\n"+ret);
  467. $("#status_warning").html(lang_failed_to_submit);
  468. $("#status_warning").show();
  469. }
  470. return false;
  471. }
  472. </script>';
  473. return $js;
  474. }
  475. /**
  476. * Returns the HTML form to upload a nano file or upload a file
  477. * @param string
  478. */
  479. public function return_form($message = null)
  480. {
  481. $params = $this->get_params(true);
  482. $url = api_get_path(WEB_AJAX_PATH).'nanogong.ajax.php?a=save_file&'.$params;
  483. //check browser support and load form
  484. $array_browser = api_browser_support('check_browser');
  485. $preview_file = $this->show_audio_file(true, true);
  486. $preview_file = Display::div(
  487. $preview_file,
  488. array('id' => 'preview', 'style' => 'text-align:center; padding-left: 25px;')
  489. );
  490. $html = '<center>';
  491. //Use normal upload file
  492. $html .= Display::return_icon('microphone.png', get_lang('PressRecordButton'),'', ICON_SIZE_BIG);
  493. $html .='<br />';
  494. $html .= '<div id="nanogong_div">';
  495. $html .= '<applet id="nanogong" archive="'.api_get_path(WEB_LIBRARY_PATH).'nanogong/nanogong.jar" code="gong.NanoGong" width="250" height="95" align="middle">';
  496. //echo '<param name="ShowRecordButton" value="false" />'; // default true
  497. // echo '<param name="ShowSaveButton" value="false" />'; //you can save in local computer | (default true)
  498. $html .= '<param name="ShowSpeedButton" value="false" />'; // default true
  499. //echo '<param name="ShowAudioLevel" value="false" />'; // it displays the audiometer | (default true)
  500. $html .= '<param name="ShowTime" value="true" />'; // default false
  501. $html .= '<param name="Color" value="#FFFFFF" />'; // default #FFFFFF
  502. //echo '<param name="StartTime" value="10.5" />';
  503. //echo '<param name="EndTime" value="65" />';
  504. $html .= '<param name="AudioFormat" value="ImaADPCM" />';// ImaADPCM (more speed), Speex (more compression)|(default Speex)
  505. //$html .= '<param name="AudioFormat" value="Speex" />';// ImaADPCM (more speed), Speex (more compression)|(default Speex)
  506. //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)
  507. //echo '<param name="MaxDuration" value="60" />';
  508. //echo '<param name="SoundFileURL" value="http://somewhere.com/mysoundfile.wav" />';//load a file |(default "")
  509. $html .= '</applet>';
  510. $html .= '<br /><br /><br />';
  511. $html .= '<form name="form_nanogong_advanced">';
  512. $html .= '<input type="hidden" name="is_nano" value="1">';
  513. $html .= '<a href="#" class="btn" onclick="send_voice()" />'.get_lang('SendRecord').'</a>';
  514. $html .= '</form></div>';
  515. $html .= Display::url(get_lang('ProblemsRecordingUploadYourOwnAudioFile'), 'javascript:void(0)', array('onclick' => 'show_simple_upload_form();'));
  516. $html .= '<br /><br /><div id="no_nanogong_div">';
  517. //$html .= Display::return_message(get_lang('BrowserNotSupportNanogongSend'), 'warning');
  518. $html .= '<form id="form_nanogong_simple" class="form-search" action="'.$url.'" name="form_nanogong" method="POST" enctype="multipart/form-data">';
  519. $html .= '<input type="file" name="file">';
  520. $html .= '<a href="#" class="btn" onclick="upload_file()" />'.get_lang('UploadFile').'</a>';
  521. $html .= '</form>';
  522. $html .= '</div>';
  523. $html .= '</center>';
  524. $html .= '<div style="display:none" id="status_ok" class="confirmation-message"></div><div style="display:none" id="status_warning" class="warning-message"></div>';
  525. $html .= '<div id="messages">'.$message.'</div>';
  526. $html .= $preview_file;
  527. return $html;
  528. }
  529. /**
  530. * @param bool $return_as_query
  531. * @return bool|string
  532. */
  533. public function get_params($return_as_query = false)
  534. {
  535. if (empty($this->params)) {
  536. return false;
  537. }
  538. if ($return_as_query) {
  539. return http_build_query($this->params);
  540. }
  541. return $this->params;
  542. }
  543. /**
  544. * @param $attribute
  545. * @return mixed
  546. */
  547. public 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. public 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. }