From 5f4c961ce2875470ba6738e0cf506f70d22b005a Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Thu, 29 Aug 2013 14:32:10 +0200 Subject: [PATCH] Adding audio recording using RTC see BT#6613 --- main/inc/ajax/lp.ajax.php | 62 ++- main/inc/lib/display.lib.php | 21 + main/inc/lib/javascript/rtc/RecordRTC.js | 475 ++++++++++++++++++ main/newscorm/learnpath.class.php | 37 +- main/newscorm/lp_add_audio.php | 65 +-- .../default/learnpath/lp_upload_audio.tpl | 1 + .../default/learnpath/record_voice.tpl | 120 +++++ 7 files changed, 737 insertions(+), 44 deletions(-) create mode 100644 main/inc/lib/javascript/rtc/RecordRTC.js create mode 100644 main/template/default/learnpath/lp_upload_audio.tpl create mode 100644 main/template/default/learnpath/record_voice.tpl diff --git a/main/inc/ajax/lp.ajax.php b/main/inc/ajax/lp.ajax.php index ec9c16ab47..5d7df12f17 100644 --- a/main/inc/ajax/lp.ajax.php +++ b/main/inc/ajax/lp.ajax.php @@ -27,7 +27,7 @@ switch ($action) { $sections = explode('^', $new_order); $new_array = array(); $i = 0; - + foreach ($sections as $items) { if (!empty($items)) { list($id, $parent_id) = explode('|', $items); @@ -54,8 +54,66 @@ switch ($action) { } Display::display_confirmation_message(get_lang('Saved')); } + break; + case 'record_audio': + if (api_is_allowed_to_edit(null, true) == false) { + exit; + } + /** @var Learnpath $lp */ + $lp = isset($_SESSION['oLP']) ? $_SESSION['oLP'] : null; + $course_info = api_get_course_info(); + + $lpPathInfo = $lp->generate_lp_folder($course_info); + + if (empty($lpPathInfo)) { + exit; + } + + require_once api_get_path(LIBRARY_PATH).'fileDisplay.lib.php'; + require_once api_get_path(LIBRARY_PATH).'document.lib.php'; + require_once api_get_path(LIBRARY_PATH) . 'fileUpload.lib.php'; + + foreach (array('video', 'audio') as $type) { + if (isset($_FILES["${type}-blob"])) { + $fileName = $_POST["${type}-filename"]; + //$file = $_FILES["${type}-blob"]["tmp_name"]; + $file = $_FILES["${type}-blob"]; + + $fileInfo = pathinfo($fileName); + + $file['name'] = 'rec_'.date('Y-m-d H:i:s').'_'.uniqid().'.'.$fileInfo['extension']; + $file['file'] = $file; + + $lpPathInfo['dir'] = api_remove_trailing_slash($lpPathInfo['dir']); + + $result = DocumentManager::upload_document( + $file, + $lpPathInfo['dir'], + $file['name'], + null, + 0, + 'overwrite', + false, + false + ); + + if (!empty($result) && is_array($result)) { + $newDocId = $result['id']; + $courseId = $result['c_id']; + + $lp->set_modified_on(); + + $lpItem = new learnpathItem($_REQUEST['lp_item_id']); + $lpItem->add_audio_from_documents($newDocId); + $data = DocumentManager::get_document_data_by_id($newDocId, $course_info['code']); + echo $data['document_url']; + exit; + } + } + } + break; default: echo ''; } -exit; \ No newline at end of file +exit; diff --git a/main/inc/lib/display.lib.php b/main/inc/lib/display.lib.php index d14367b035..fefedb6bc1 100644 --- a/main/inc/lib/display.lib.php +++ b/main/inc/lib/display.lib.php @@ -1550,4 +1550,25 @@ class Display { '; return $html; } + + public static function getMediaPlayer($file, $params = array()) + { + $fileInfo = pathinfo($file); + + switch ($fileInfo['extension']) { + case 'mp3': + case 'webm': + $autoplay = null; + if (isset($params['autoplay']) && $params['autoplay'] == 'true') { + $autoplay = 'autoplay'; + } + $width = isset($params['width']) ? 'width="'.$params['width'].'"' : null; + $html = '