dropbox.ajax.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Responses to AJAX calls for the document upload
  5. */
  6. require_once '../global.inc.php';
  7. require_once api_get_path(SYS_CODE_PATH).'dropbox/dropbox_functions.inc.php';
  8. $action = $_REQUEST['a'];
  9. switch ($action) {
  10. case 'upload_file':
  11. api_protect_course_script(true);
  12. // User access same as upload.php
  13. $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
  14. $recipients = isset($_POST['recipients']) ? $_POST['recipients'] : '';
  15. if (empty($recipients)) {
  16. $resultList[] = ['error' => get_lang('YouMustSelectAtLeastOneDestinee')];
  17. echo json_encode(['files' => $resultList]);
  18. exit;
  19. }
  20. if (!empty($_FILES)) {
  21. $files = $_FILES['files'];
  22. $fileList = [];
  23. foreach ($files as $name => $array) {
  24. $counter = 0;
  25. foreach ($array as $data) {
  26. $fileList[$counter][$name] = $data;
  27. $counter++;
  28. }
  29. }
  30. $resultList = [];
  31. foreach ($fileList as $file) {
  32. $globalFile = [];
  33. $globalFile['files'] = $file;
  34. /** @var Dropbox_SentWork $result */
  35. $result = store_add_dropbox($file);
  36. $json = array();
  37. if (!empty($result)) {
  38. $json['name'] = Display::url(
  39. api_htmlentities($result->title),
  40. api_htmlentities(api_get_path(WEB_CODE_PATH).'dropbox/index.php?'.api_get_cidreq()),
  41. array('target' => '_blank')
  42. );
  43. $json['url'] = api_get_path(WEB_CODE_PATH).'dropbox/index.php?'.api_get_cidreq();
  44. $json['size'] = format_file_size($result->filesize);
  45. $json['type'] = api_htmlentities($file['type']);
  46. $json['result'] = Display::return_icon(
  47. 'accept.png',
  48. get_lang('Uploaded')
  49. );
  50. } else {
  51. $json['result'] = Display::return_icon(
  52. 'exclamation.png',
  53. get_lang('Error')
  54. );
  55. }
  56. $resultList[] = $json;
  57. }
  58. echo json_encode(['files' => $resultList]);
  59. }
  60. exit;
  61. break;
  62. }
  63. exit;