nanogong.lib.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Class Nanogong
  5. *
  6. * Files are saved in the path:
  7. * courses/XXX/exercises/(session_id)/(exercise_id)/(question_id)/(user_id)/
  8. *
  9. * The file name is composed with:
  10. * (course_id)/(session_id)/(user_id)/(exercise_id)/(question_id)/(exe_id).wav|mp3|ogg
  11. *
  12. *
  13. */
  14. class Nanogong
  15. {
  16. public $filename;
  17. public $store_filename;
  18. public $store_path;
  19. public $params;
  20. public $can_edit = false;
  21. public $course_id;
  22. public $session_id;
  23. public $exercise_id;
  24. public $question_id;
  25. public $user_id;
  26. public $course_info;
  27. /* Files allowed to upload */
  28. public $available_extensions = array('mp3', 'wav', 'ogg');
  29. /**
  30. * @param array $params
  31. */
  32. public function __construct($params = array())
  33. {
  34. $this->set_parameters($params);
  35. }
  36. /**
  37. * @return bool
  38. */
  39. public function create_user_folder()
  40. {
  41. //COURSE123/exercises/session_id/exercise_id/question_id/user_id
  42. if (empty($this->store_path)) {
  43. return false;
  44. }
  45. // Trying to create the courses/COURSE123/exercises/ dir just in case.
  46. $directoryPermissions = api_get_permissions_for_new_directories();
  47. if (!is_dir($this->store_path)) {
  48. mkdir($this->store_path, $directoryPermissions);
  49. }
  50. if (!is_dir($this->store_path.$this->session_id)) {
  51. mkdir($this->store_path.$this->session_id, $directoryPermissions);
  52. }
  53. if (!is_dir($this->store_path.$this->session_id.'/'.$this->exercise_id)) {
  54. mkdir($this->store_path.$this->session_id.'/'.$this->exercise_id, $directoryPermissions);
  55. }
  56. if (!is_dir($this->store_path.$this->session_id.'/'.$this->exercise_id.'/'.$this->question_id)
  57. ) {
  58. mkdir($this->store_path.$this->session_id.'/'.$this->exercise_id.'/'.$this->question_id, $directoryPermissions);
  59. }
  60. if (!empty($this->user_id) &&
  61. !is_dir($this->store_path.$this->session_id.'/'.$this->exercise_id.'/'.$this->question_id.'/'.$this->user_id)
  62. ) {
  63. mkdir($this->store_path.$this->session_id.'/'.$this->exercise_id.'/'.$this->question_id.'/'.$this->user_id, $directoryPermissions);
  64. }
  65. }
  66. /**
  67. * Setting parameters: course id, session id, etc
  68. * @param array
  69. */
  70. public function set_parameters($params = array())
  71. {
  72. // Setting course id
  73. if (isset($params['course_id'])) {
  74. $this->course_id = intval($params['course_id']);
  75. } else {
  76. $this->course_id = $params['course_id'] = api_get_course_int_id();
  77. }
  78. //Setting course info
  79. if (isset($this->course_id)) {
  80. $this->course_info = api_get_course_info_by_id($this->course_id);
  81. }
  82. //Setting session id
  83. if (isset($params['session_id'])) {
  84. $this->session_id = intval($params['session_id']);
  85. } else {
  86. $this->session_id = $params['session_id'] = api_get_session_id();
  87. }
  88. //Setting user ids
  89. if (isset($params['user_id'])) {
  90. $this->user_id = intval($params['user_id']);
  91. } else {
  92. $this->user_id = $params['user_id'] = api_get_user_id();
  93. }
  94. //Setting user ids
  95. if (isset($params['exercise_id'])) {
  96. $this->exercise_id = intval($params['exercise_id']);
  97. } else {
  98. $this->exercise_id = 0;
  99. }
  100. //Setting user ids
  101. if (isset($params['question_id'])) {
  102. $this->question_id = intval($params['question_id']);
  103. } else {
  104. $this->question_id = 0;
  105. }
  106. $this->can_edit = false;
  107. if (api_is_allowed_to_edit()) {
  108. $this->can_edit = true;
  109. } else {
  110. if ($this->user_id == api_get_user_id()) {
  111. $this->can_edit = true;
  112. }
  113. }
  114. // Settings the params array
  115. $this->params = $params;
  116. $this->store_path = api_get_path(SYS_COURSE_PATH).$this->course_info['path'].'/exercises/';
  117. $this->create_user_folder();
  118. $this->store_path = $this->store_path.implode('/', array($this->session_id, $this->exercise_id, $this->question_id, $this->user_id)).'/';
  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. ) {
  210. $attempt_table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
  211. $sql = "SELECT filename FROM $attempt_table
  212. WHERE
  213. exe_id = ".$this->params['exe_id']." AND
  214. user_id = ".$this->params['user_id']." AND
  215. question_id = ".$this->params['question_id']." AND
  216. session_id = ".$this->params['session_id']." AND
  217. course_code = '".$this->course_info['code']."'
  218. LIMIT 1";
  219. $result = Database::query($sql);
  220. $result = Database::fetch_row($result,'ASSOC');
  221. if (isset($result) && isset($result[0]) && !empty($result[0])) {
  222. $filename = $result[0];
  223. }
  224. }
  225. }
  226. if (is_file($this->store_path.$filename)) {
  227. return $this->store_path.$filename;
  228. }
  229. return null;
  230. }
  231. /**
  232. *
  233. * Get the URL of the file
  234. * path courses/XXX/exercises/(session_id)/(exercise_id)/(question_id)/(user_id)/
  235. * @param int $force_download
  236. *
  237. * @return string
  238. */
  239. public function get_public_url($force_download = 0)
  240. {
  241. $params = $this->get_params();
  242. $filename = basename($this->load_filename_if_exists());
  243. $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;
  244. return $url;
  245. }
  246. /**
  247. * Uploads the nanogong wav file
  248. * @param bool
  249. */
  250. public function upload_file($is_nano = false)
  251. {
  252. if (!empty($_FILES)) {
  253. $upload_ok = process_uploaded_file($_FILES['file'], false);
  254. if (!is_uploaded_file($_FILES['file']['tmp_name'])) {
  255. return 0;
  256. }
  257. if ($upload_ok) {
  258. // Check if there is enough space to save the file
  259. if (!DocumentManager::enough_space($_FILES['file']['size'], DocumentManager::get_course_quota())) {
  260. return 0;
  261. }
  262. //first we delete everything before uploading the file
  263. $this->delete_files();
  264. //Reload the filename variable
  265. $file_name = add_ext_on_mime($_FILES['file']['name'], $_FILES['file']['type']);
  266. $file_name = strtolower($file_name);
  267. $file_info = pathinfo($file_name);
  268. if ($is_nano == true) {
  269. $file_info['extension'] = 'wav';
  270. }
  271. $file_name = $this->filename.'.'.$file_info['extension'];
  272. if (in_array($file_info['extension'], $this->available_extensions)) {
  273. if (move_uploaded_file($_FILES['file']['tmp_name'], $this->store_path.$file_name)) {
  274. $this->store_filename = $this->store_path.$file_name;
  275. return 1;
  276. }
  277. }
  278. }
  279. }
  280. return 0;
  281. }
  282. /**
  283. * Show the audio file + a button to download
  284. * @param bool
  285. */
  286. public function show_audio_file($show_delete_button = false)
  287. {
  288. $html = '';
  289. $file_path = $this->load_filename_if_exists();
  290. if (!empty($file_path)) {
  291. $url = $this->get_public_url(true);
  292. $actions = Display::url(Display::return_icon('save.png', get_lang('Download'), array(), ICON_SIZE_SMALL), $url, array('target'=>'_blank'));
  293. $download_button = Display::url(get_lang('Download'), $url, array('class' =>'btn btn-default'));
  294. if ($show_delete_button) {
  295. $actions .= ' '.Display::url(Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL), "#", array('onclick'=>'delete_file();'));
  296. }
  297. $basename = basename($file_path);
  298. $path_info = pathinfo($basename);
  299. if ($path_info['extension'] == 'wav') {
  300. $html .= '<script>
  301. $(document).ready( function() {
  302. var java_enabled = navigator.javaEnabled();
  303. if (java_enabled) {
  304. $("#nanogong_warning").hide();
  305. $("#nanogong_player_id").show();
  306. } else {
  307. $("#nanogong_warning").show();
  308. $("#nanogong_player_id").hide();
  309. }
  310. });
  311. </script>';
  312. $html .= '<div id="nanogong_player_id" class="nanogong_player_container">';
  313. $html .= '<div class="action_player">'.$actions.'</div>';
  314. $html .= '<div class="nanogong_player">';
  315. $html .= '<applet id="nanogong_player" archive="'.api_get_path(WEB_LIBRARY_PATH).'nanogong/nanogong.jar" code="gong.NanoGong" width="250" height="95" ALIGN="middle">';
  316. $html .= '<param name="ShowRecordButton" value="false" />'; // default true
  317. $html .= '<param name="ShowSaveButton" value="false" />'; //you can save in local computer | (default true)
  318. //echo '<param name="ShowAudioLevel" value="false" />'; // it displays the audiometer | (default true)
  319. $html .= '<param name="ShowTime" value="true" />'; // default false
  320. $html .= '<param name="Color" value="#FFFFFF" />';
  321. $html .= '<param name="ShowSpeedButton" value="false" />';
  322. //echo '<param name="StartTime" value="10.5" />';
  323. //echo '<param name="EndTime" value="65" />';
  324. $html .= '<param name="AudioFormat" value="ImaADPCM" />';// ImaADPCM (more speed), Speex (more compression)|(default Speex)
  325. //$html .= '<param name="AudioFormat" value="Speex" />';// ImaADPCM (more speed), Speex (more compression)|(default Speex)
  326. //Quality for ImaADPCM (low 8000, medium 11025, normal 22050, hight 44100) OR Quality for Speex (low 8000, medium 16000, normal 32000, hight 44100) | (default 44100)
  327. //echo '<param name="SamplingRate" value="32000" />';
  328. //echo '<param name="MaxDuration" value="60" />';
  329. $html .= '<param name="SoundFileURL" value="'.$url.'" />';//load a file |(default "")
  330. $html .= '</applet>';
  331. $html .= '</div>';
  332. $html .= '</div>';
  333. $html .= '<div id="nanogong_warning">'.Display::return_message(get_lang('BrowserDoesNotSupportNanogongPlayer'), 'warning').$download_button.'</div>';
  334. } elseif(in_array($path_info['extension'],array('mp3', 'ogg','wav'))) {
  335. $js_path = api_get_path(WEB_LIBRARY_PATH).'javascript/';
  336. $html .= '<link rel="stylesheet" href="'.$js_path.'jquery-jplayer/skin/blue.monday/css/jplayer.blue.monday.css" type="text/css">';
  337. $html .= '<script type="text/javascript" src="'.$js_path.'jquery-jplayer/jplayer/jquery.jplayer.min.js"></script>';
  338. $html .= '<div class="nanogong_player"></div>';
  339. $html .= '<br /><div class="action_player">'.$actions.'</div><br /><br /><br />';
  340. $params = array(
  341. 'url' => $url,
  342. 'extension' =>$path_info['extension'],
  343. 'count'=> 1
  344. );
  345. $jquery = DocumentManager::generate_jplayer_jquery($params);
  346. $html .= '<script>
  347. $(document).ready( function() {
  348. //Experimental changes to preview mp3, ogg files
  349. '.$jquery.'
  350. });
  351. </script>';
  352. $html .= DocumentManager::generate_media_preview(1, 'advanced');
  353. }
  354. }
  355. return $html;
  356. }
  357. /*
  358. var filename = document.getElementById("audio_title").value+".wav";
  359. var filename = filename.replace(/\s/g, "_");//replace spaces by _
  360. var filename = encodeURIComponent(filename);
  361. var filepath="'.urlencode($filepath).'";
  362. var dir="'.urlencode($dir).'";
  363. var course_code="'.urlencode($course_code).'";
  364. var urlnanogong="'.$url.'?filename="+filename+"&filepath="+filepath+"&dir="+dir+"&course_code="+course_code;
  365. */
  366. /**
  367. * Returns the nanogong javascript code
  368. * @return string
  369. */
  370. public function return_js()
  371. {
  372. $params = $this->get_params(true);
  373. $url = api_get_path(WEB_AJAX_PATH).'nanogong.ajax.php?a=save_file&'.$params.'&is_nano=1';
  374. $url_load_file = api_get_path(WEB_AJAX_PATH).'nanogong.ajax.php?a=show_audio&'.$params;
  375. $url_delete = api_get_path(WEB_AJAX_PATH).'nanogong.ajax.php?a=delete&'.$params;
  376. $js = '<script language="javascript">
  377. //lang vars
  378. var lang_no_applet = "'.get_lang('NanogongNoApplet').'";
  379. var lang_record_before_save = "'.get_lang('NanogongRecordBeforeSave').'";
  380. var lang_give_a_title = "'.get_lang('NanogongGiveTitle').'";
  381. var lang_failed_to_submit = "'.get_lang('NanogongFailledToSubmit').'";
  382. var lang_submitted = "'.get_lang('NanogongSubmitted').'";
  383. var lang_deleted = "'.get_lang('Deleted').'";
  384. var is_nano = 0;
  385. function check_gong() {
  386. //var record = document.getElementById("nanogong");
  387. var recorder;
  388. var java_enabled = navigator.javaEnabled()
  389. return java_enabled;
  390. }
  391. function show_simple_upload_form() {
  392. $("#no_nanogong_div").show();
  393. //$("#nanogong_div").hide();
  394. $("#preview").hide();
  395. }
  396. $(document).ready( function() {
  397. $("#no_nanogong_div").hide();
  398. $("#nanogong_div").hide();
  399. var check_js = check_gong();
  400. if (check_js == true) {
  401. $("#nanogong_div").show();
  402. $("#no_nanogong_div").hide();
  403. is_nano = 1;
  404. $(".nanogong_player").show();
  405. } else {
  406. $("#no_nanogong_div").show();
  407. $("#nanogong_div").hide();
  408. $(".nanogong_player").hide();
  409. }
  410. //show always the mp3/ogg upload form (for dev purposes)
  411. //$("#no_nanogong_div").show();
  412. //$("#nanogong_div").hide();
  413. });
  414. function delete_file() {
  415. $.ajax({
  416. url: "'.$url_delete.'",
  417. success:function(data) {
  418. $("#status_warning").hide();
  419. $("#status_ok").hide();
  420. $("#messages").html(data);
  421. $("#messages").show();
  422. $("#preview").hide();
  423. }
  424. });
  425. }
  426. function upload_file() {
  427. $("#form_nanogong_simple").submit();
  428. }
  429. function send_voice() {
  430. $("#status_warning").hide();
  431. $("#status_ok").hide();
  432. $("#messages").hide();
  433. var check_js = check_gong();
  434. var recorder = document.getElementById("nanogong");
  435. if (!recorder || !check_js) {
  436. //alert(lang_no_applet)
  437. $("#status_warning").html(lang_no_applet);
  438. $("#status_warning").show();
  439. //Show form
  440. $("#no_nanogong_div").show();
  441. $("#nanogong_div").hide();
  442. return false;
  443. }
  444. var duration = parseInt(recorder.sendGongRequest("GetMediaDuration", "audio")) || 0;
  445. if (duration <= 0) {
  446. $("#status_warning").html(lang_record_before_save);
  447. $("#status_warning").show();
  448. return false;
  449. }
  450. var applet = document.getElementById("nanogong");
  451. var ret = applet.sendGongRequest("PostToForm", "'.$url.'", "file", "", "temp"); // PostToForm, postURL, inputname, cookie, filename
  452. if (ret == 1) {
  453. $("#status_ok").html(lang_submitted);
  454. $("#status_ok").show();
  455. $.ajax({
  456. url:"'.$url_load_file.'&is_nano="+is_nano,
  457. success: function(data){
  458. $("#preview").html(data);
  459. $("#preview").show();
  460. }
  461. });
  462. } else {
  463. //alert(lang_submitted+"\n"+ret);
  464. $("#status_warning").html(lang_failed_to_submit);
  465. $("#status_warning").show();
  466. }
  467. return false;
  468. }
  469. </script>';
  470. return $js;
  471. }
  472. /**
  473. * Returns the HTML form to upload a nano file or upload a file
  474. * @param string
  475. */
  476. public function return_form($message = null)
  477. {
  478. $params = $this->get_params(true);
  479. $url = api_get_path(WEB_AJAX_PATH).'nanogong.ajax.php?a=save_file&'.$params;
  480. //check browser support and load form
  481. $array_browser = api_browser_support('check_browser');
  482. $preview_file = $this->show_audio_file(true, true);
  483. $preview_file = Display::div(
  484. $preview_file,
  485. array('id' => 'preview', 'style' => 'text-align:center; padding-left: 25px;')
  486. );
  487. $html = '<center>';
  488. //Use normal upload file
  489. $html .= Display::return_icon('microphone.png', get_lang('PressRecordButton'),'', ICON_SIZE_BIG);
  490. $html .='<br />';
  491. $html .= '<div id="nanogong_div">';
  492. $html .= '<applet id="nanogong" archive="'.api_get_path(WEB_LIBRARY_PATH).'nanogong/nanogong.jar" code="gong.NanoGong" width="250" height="95" align="middle">';
  493. //echo '<param name="ShowRecordButton" value="false" />'; // default true
  494. // echo '<param name="ShowSaveButton" value="false" />'; //you can save in local computer | (default true)
  495. $html .= '<param name="ShowSpeedButton" value="false" />'; // default true
  496. //echo '<param name="ShowAudioLevel" value="false" />'; // it displays the audiometer | (default true)
  497. $html .= '<param name="ShowTime" value="true" />'; // default false
  498. $html .= '<param name="Color" value="#FFFFFF" />'; // default #FFFFFF
  499. //echo '<param name="StartTime" value="10.5" />';
  500. //echo '<param name="EndTime" value="65" />';
  501. $html .= '<param name="AudioFormat" value="ImaADPCM" />';// ImaADPCM (more speed), Speex (more compression)|(default Speex)
  502. //$html .= '<param name="AudioFormat" value="Speex" />';// ImaADPCM (more speed), Speex (more compression)|(default Speex)
  503. //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)
  504. //echo '<param name="MaxDuration" value="60" />';
  505. //echo '<param name="SoundFileURL" value="http://somewhere.com/mysoundfile.wav" />';//load a file |(default "")
  506. $html .= '</applet>';
  507. $html .= '<br /><br /><br />';
  508. $html .= '<form name="form_nanogong_advanced">';
  509. $html .= '<input type="hidden" name="is_nano" value="1">';
  510. $html .= '<a href="#" class="btn btn-default" onclick="send_voice()" />'.get_lang('SendRecord').'</a>';
  511. $html .= '</form></div>';
  512. $html .= Display::url(get_lang('ProblemsRecordingUploadYourOwnAudioFile'), 'javascript:void(0)', array('onclick' => 'show_simple_upload_form();'));
  513. $html .= '<br /><br /><div id="no_nanogong_div">';
  514. //$html .= Display::return_message(get_lang('BrowserNotSupportNanogongSend'), 'warning');
  515. $html .= '<form id="form_nanogong_simple" class="form-search" action="'.$url.'" name="form_nanogong" method="POST" enctype="multipart/form-data">';
  516. $html .= '<input type="file" name="file">';
  517. $html .= '<a href="#" class="btn btn-default" onclick="upload_file()" /><em class="fa fa-upload"></em> '.get_lang('UploadFile').'</a>';
  518. $html .= '</form>';
  519. $html .= '</div>';
  520. $html .= '</center>';
  521. $html .= '<div style="display:none" id="status_ok" class="confirmation-message"></div><div style="display:none" id="status_warning" class="warning-message"></div>';
  522. $html .= '<div id="messages">'.$message.'</div>';
  523. $html .= $preview_file;
  524. return $html;
  525. }
  526. /**
  527. * @param bool $return_as_query
  528. * @return bool|string
  529. */
  530. public function get_params($return_as_query = false)
  531. {
  532. if (empty($this->params)) {
  533. return false;
  534. }
  535. if ($return_as_query) {
  536. return http_build_query($this->params);
  537. }
  538. return $this->params;
  539. }
  540. /**
  541. * @param $attribute
  542. * @return mixed
  543. */
  544. public function get_param_value($attribute)
  545. {
  546. if (isset($this->params[$attribute])) {
  547. return $this->params[$attribute];
  548. }
  549. }
  550. /**
  551. * Show a button to load the form
  552. * @return string
  553. */
  554. public function show_button()
  555. {
  556. $params_string = $this->get_params(true);
  557. $url = api_get_path(WEB_AJAX_PATH)
  558. . 'nanogong.ajax.php?a=show_form&'
  559. . $params_string
  560. . '&TB_iframe=true';
  561. $html = Display::url(
  562. get_lang('RecordAnswer'),
  563. $url,
  564. [
  565. 'class' => 'btn btn-default ajax',
  566. 'data-title' => get_lang('RecordAnswer')
  567. ]
  568. );
  569. $html .= '<br /><br />'.Display::return_message(get_lang('UseTheMessageBelowToAddSomeComments'));
  570. return $html;
  571. }
  572. }