nanogong.lib.php 22 KB

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