nanogong.lib.php 21 KB

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