nanogong.ajax.php 3.0 KB

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