nanogong.ajax.php 3.1 KB

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