record_audio_rtc.ajax.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. $audioDir = Security::remove_XSS($audioDir);
  19. $dirBaseDocuments = api_get_path(SYS_COURSE_PATH).$courseInfo['path'].'/document';
  20. $saveDir = $dirBaseDocuments.$audioDir;
  21. if (!is_dir($saveDir)) {
  22. mkdir($saveDir, api_get_permissions_for_new_directories(), true);
  23. }
  24. $file['file'] = $file;
  25. $result = DocumentManager::upload_document(
  26. $file,
  27. $audioDir,
  28. $file['name'],
  29. null,
  30. 0,
  31. 'overwrite',
  32. false,
  33. false
  34. );
  35. if (!empty($result) && is_array($result)) {
  36. $newDocId = $result['id'];
  37. $courseId = $result['c_id'];
  38. /** @var learnpath $lp */
  39. $lp = Session::read('oLP');
  40. $lpItemId = isset($_REQUEST['lp_item_id']) && !empty($_REQUEST['lp_item_id']) ? $_REQUEST['lp_item_id'] : null;
  41. if (!empty($lp) && empty($lpItemId)) {
  42. $lp->set_modified_on();
  43. $lpItem = new learnpathItem($lpItemId);
  44. $lpItem->add_audio_from_documents($newDocId);
  45. }
  46. $data = DocumentManager::get_document_data_by_id($newDocId, $courseInfo['code']);
  47. Display::addFlash(
  48. Display::return_message(get_lang('DocumentCreated'), 'success')
  49. );
  50. echo $data['document_url'];
  51. exit;
  52. }