record_audio_rtc.ajax.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use ChamiloSession as Session;
  4. require_once __DIR__.'/../global.inc.php';
  5. // Add security from Chamilo
  6. api_protect_course_script();
  7. api_block_anonymous_users();
  8. $courseInfo = api_get_course_info();
  9. if (!isset($_FILES['audio_blob'], $_REQUEST['audio_dir'])) {
  10. api_not_allowed();
  11. }
  12. $file = $_FILES['audio_blob'];
  13. $audioDir = Security::remove_XSS($_REQUEST['audio_dir']);
  14. $userId = api_get_user_id();
  15. if (empty($userId)) {
  16. api_not_allowed();
  17. }
  18. $audioFileName = Security::remove_XSS($file['name']);
  19. $audioFileName = Database::escape_string($audioFileName);
  20. $audioFileName = api_replace_dangerous_char($audioFileName);
  21. $audioFileName = disable_dangerous_file($audioFileName);
  22. $audioDir = Security::remove_XSS($audioDir);
  23. $dirBaseDocuments = api_get_path(SYS_COURSE_PATH).$courseInfo['path'].'/document';
  24. $saveDir = $dirBaseDocuments.$audioDir;
  25. if (!is_dir($saveDir)) {
  26. DocumentManager::createDefaultAudioFolder($courseInfo);
  27. }
  28. $documentPath = $saveDir.'/'.$audioFileName;
  29. $file['file'] = $file;
  30. $result = DocumentManager::upload_document(
  31. $file,
  32. $audioDir,
  33. $file['name'],
  34. null,
  35. 0,
  36. 'overwrite',
  37. false,
  38. false
  39. );
  40. if (!empty($result) && is_array($result)) {
  41. $newDocId = $result['id'];
  42. $courseId = $result['c_id'];
  43. /** @var learnpath $lp */
  44. $lp = Session::read('oLP');
  45. $lpItemId = isset($_REQUEST['lp_item_id']) && !empty($_REQUEST['lp_item_id']) ? $_REQUEST['lp_item_id'] : null;
  46. if (!empty($lp) && empty($lpItemId)) {
  47. $lp->set_modified_on();
  48. $lpItem = new learnpathItem($lpItemId);
  49. $lpItem->add_audio_from_documents($newDocId);
  50. }
  51. $data = DocumentManager::get_document_data_by_id($newDocId, $courseInfo['code']);
  52. Display::addFlash(
  53. Display::return_message(get_lang('DocumentCreated'), 'success')
  54. );
  55. echo $data['document_url'];
  56. exit;
  57. }