nanogong.ajax.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Responses to AJAX calls
  5. */
  6. require_once '../global.inc.php';
  7. //@todo for some reason nanogong doesn't like this variables
  8. //api_protect_course_script(true);
  9. $action = $_REQUEST['a'];
  10. unset($_REQUEST['a']);
  11. $js_path = api_get_path(WEB_LIBRARY_PATH).'javascript/';
  12. //Fix in order to add the exe_id
  13. if (isset($_REQUEST['from_htaccess'])) {
  14. if (isset($_REQUEST['file'])) {
  15. $fileinfo = pathinfo($_REQUEST['file']);
  16. $items = explode('-', $fileinfo['filename']);
  17. $_REQUEST['exe_id'] = $items[5];
  18. }
  19. }
  20. $nano = new Nanogong($_REQUEST);
  21. $is_nano = false;
  22. if (isset($_REQUEST['is_nano'])) {
  23. $is_nano = true;
  24. }
  25. switch ($action) {
  26. case 'get_file':
  27. if ($nano->get_param_value('user_id') == api_get_user_id() || api_is_allowed_to_edit()) {
  28. $file_path = $nano->load_filename_if_exists();
  29. //$file_path = '/var/www/rocio/courses/GREAT123/exercises/0/2/5/1/1-0-1-2-5-38.mp3';
  30. if ($file_path) {
  31. $info = pathinfo($file_path);
  32. $user_info = api_get_user_info($nano->params['user_id']);
  33. $name = get_lang('Quiz').'-'.$user_info['firstname'].'-'.$user_info['lastname'].'.'.$info['extension'];
  34. $download = true;
  35. if (isset($_REQUEST['download']) && $_REQUEST['download'] == 0) {
  36. $download = false;
  37. }
  38. DocumentManager::file_send_for_download($file_path, $download);
  39. exit;
  40. }
  41. }
  42. break;
  43. case 'show_audio':
  44. if (!$is_nano) {
  45. echo $nano->return_js($_REQUEST);
  46. }
  47. echo $nano->show_audio_file($is_nano);
  48. break;
  49. case 'delete':
  50. $return = $nano->delete_files();
  51. if ($return == 1) {
  52. //cant' do this because the post that nano send doesnt take into account the session
  53. Display::display_confirmation_message(get_lang('FileDeleted'));
  54. } else {
  55. Display::display_confirmation_message(get_lang('FileNotFound'));
  56. }
  57. break;
  58. case 'show_form':
  59. api_protect_course_script(true);
  60. Display::display_reduced_header();
  61. echo $nano->return_js($_REQUEST);
  62. echo $nano->return_form();
  63. break;
  64. case 'save_file':
  65. //User access same as upload.php
  66. $return = $nano->upload_file($is_nano);
  67. if ($is_nano) {
  68. //nano looks for numbers
  69. if ($return == 1) {
  70. //cant' do this because the post that nano send doesnt take into account the session
  71. echo 1; //Display::display_confirmation_message(get_lang('UplUploadSucceeded'));
  72. } else {
  73. echo 0;
  74. //Display::display_warning_message(get_lang('UplUnableToSaveFileFilteredExtension'));
  75. }
  76. } else {
  77. Display::display_reduced_header();
  78. echo $nano->return_js($_REQUEST);
  79. //normal form
  80. if ($return == 1) {
  81. //cant' do this because the post that nano send doesnt take into account the session
  82. $message = Display::return_message(get_lang('UplUploadSucceeded'), 'confirm');
  83. } else {
  84. $message = Display::return_message(get_lang('UplUnableToSaveFileFilteredExtension'), 'warning');
  85. }
  86. echo $nano->return_form($message);
  87. }
  88. break;
  89. default:
  90. echo '';
  91. }
  92. exit;