lp_add_audio.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This is a learning path creation and player tool in Chamilo - previously
  5. * @author Julio Montoya - Improving the list of templates
  6. * @package chamilo.learnpath
  7. */
  8. $this_section = SECTION_COURSES;
  9. api_protect_course_script();
  10. require_once 'learnpath_functions.inc.php';
  11. require_once 'resourcelinker.inc.php';
  12. $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
  13. $isStudentView = isset($_REQUEST['isStudentView']) ? (int)$_REQUEST['isStudentView'] : null;
  14. $learnpath_id = (int)$_REQUEST['lp_id'];
  15. $submit = isset($_POST['submit_button']) ? $_POST['submit_button'] : null;
  16. $type = isset($_GET['type']) ? $_GET['type'] : null;
  17. $action = isset($_GET['action']) ? $_GET['action'] : null;
  18. // Using the resource linker as a tool for adding resources to the learning path.
  19. if ($action == 'add' && $type == 'learnpathitem') {
  20. $htmlHeadXtra[] = "<script>
  21. window.location=\"../resourcelinker/resourcelinker.php?source_id=5&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no\";
  22. </script>";
  23. }
  24. if ((!$is_allowed_to_edit) || ($isStudentView)) {
  25. error_log('New LP - User not authorized in lp_add_item.php');
  26. header('location:lp_controller.php?action=view&lp_id='.$learnpath_id);
  27. exit;
  28. }
  29. /* SHOWING THE ADMIN TOOLS */
  30. if (isset($_SESSION['gradebook'])) {
  31. $gradebook = $_SESSION['gradebook'];
  32. }
  33. if (!empty($gradebook) && $gradebook == 'view') {
  34. $interbreadcrumb[] = array (
  35. 'url' => '../gradebook/'.$_SESSION['gradebook_dest'],
  36. 'name' => get_lang('ToolGradebook')
  37. );
  38. }
  39. $interbreadcrumb[] = array('url' => 'lp_controller.php?action=list', 'name' => get_lang('LearningPaths'));
  40. $interbreadcrumb[] = array('url' => api_get_self()."?action=build&lp_id=$learnpath_id", 'name' => $_SESSION['oLP']->get_name());
  41. switch ($type) {
  42. case 'dir':
  43. $interbreadcrumb[] = array(
  44. 'url' => 'lp_controller.php?action=add_item&type=step&lp_id='.$_SESSION['oLP']->get_id().'&'.api_get_cidreq(),
  45. 'name' => get_lang('NewStep'),
  46. );
  47. $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('NewChapter'));
  48. break;
  49. case 'document':
  50. $interbreadcrumb[] = array(
  51. 'url' => 'lp_controller.php?action=add_item&type=step&lp_id='.$_SESSION['oLP']->get_id().'&'.api_get_cidreq(),
  52. 'name' => get_lang('NewStep'),
  53. );
  54. break;
  55. default:
  56. $interbreadcrumb[]= array('url' => '#', 'name' => get_lang('NewStep'));
  57. break;
  58. }
  59. if ($action == 'add_item' && $type == 'document') {
  60. $interbreadcrumb[]= array ('url' => '#', 'name' => get_lang('NewDocumentCreated'));
  61. }
  62. // Theme calls.
  63. $show_learn_path = true;
  64. $lp_item_id = isset($_GET['id']) ? intval($_GET['id']) : null;
  65. if (empty($lp_item_id)) {
  66. api_not_allowed();
  67. }
  68. $courseInfo = api_get_course_info();
  69. $lp_item = new learnpathItem($lp_item_id);
  70. $form = new FormValidator(
  71. 'add_audio',
  72. 'post',
  73. api_get_self() . '?action=add_audio&id=' . $lp_item_id . '&' . api_get_cidreq().'&lp_id='.$learnpath_id,
  74. null,
  75. array('enctype' => 'multipart/form-data')
  76. );
  77. $suredel = trim(get_lang('AreYouSureToDeleteJS'));
  78. $lpPathInfo = $_SESSION['oLP']->generate_lp_folder(api_get_course_info());
  79. $file = null;
  80. if (isset($lp_item->audio) && !empty($lp_item->audio)) {
  81. $file = api_get_path(SYS_COURSE_PATH).$courseInfo['path'].'/document/audio/'.$lp_item->audio;
  82. $urlFile = api_get_path(WEB_COURSE_PATH).$courseInfo['path'].'/document/audio/'.$lp_item->audio.'?'.api_get_cidreq();
  83. if (!file_exists($file)) {
  84. $file = api_get_path(SYS_COURSE_PATH).$courseInfo['path'].'/document'.$lpPathInfo['dir'] . '/' . $lp_item->audio;
  85. $urlFile = api_get_path(WEB_COURSE_PATH).$courseInfo['path'].'/document'.$lpPathInfo['dir'] . '/' . $lp_item->audio.'?'.api_get_cidreq();
  86. }
  87. }
  88. $page = $_SESSION['oLP']->build_action_menu(true);
  89. $page .= '<div class="row" style="overflow:hidden">';
  90. $page .= '<div id="lp_sidebar" class="col-md-4">';
  91. $page .= $_SESSION['oLP']->return_new_tree(null, true);
  92. // Show the template list.
  93. $page .= '</div>';
  94. $recordVoiceForm = Display::page_subheader(get_lang('RecordYourVoice'));
  95. $page .= '<div id="doc_form" class="col-md-8">';
  96. $htmlHeadXtra[] = '<script src="' . api_get_path(WEB_LIBRARY_JS_PATH) . 'rtc/RecordRTC.js"></script>';
  97. $htmlHeadXtra[] = '<script src="' . api_get_path(WEB_LIBRARY_PATH) . 'wami-recorder/recorder.js"></script>';
  98. $htmlHeadXtra[] = '<script src="' . api_get_path(WEB_LIBRARY_PATH) . 'wami-recorder/gui.js"></script>';
  99. $htmlHeadXtra[] = '<script type="text/javascript" src="' . api_get_path(WEB_LIBRARY_PATH) . 'swfobject/swfobject.js"></script>';
  100. $tpl = new Template(null);
  101. $tpl->assign('unique_file_id', api_get_unique_id());
  102. $tpl->assign('course_code', api_get_course_id());
  103. $tpl->assign('php_session_id', session_id());
  104. $tpl->assign('filename', $lp_item->get_title().'_nano.wav');
  105. $tpl->assign('enable_record_audio', api_get_setting('enable_record_audio') === 'true');
  106. $tpl->assign('cur_dir_path', '/audio');
  107. $tpl->assign('lp_item_id', $lp_item_id);
  108. $tpl->assign('lp_dir', api_remove_trailing_slash($lpPathInfo['dir']));
  109. $recordVoiceForm .= $tpl->fetch('default/learnpath/record_voice.tpl');
  110. $form->addElement('header', get_lang('Or'));
  111. $form->addElement('header', get_lang('AudioFile'));
  112. $form->addLabel(null, sprintf(get_lang('AudioFileForItemX'), $lp_item->get_title()));
  113. if (!empty($file)) {
  114. $audioPlayer = '<div id="preview">'.
  115. Display::getMediaPlayer($file, array('url' => $urlFile)).
  116. "</div>";
  117. $form->addElement('label', get_lang('Listen'), $audioPlayer);
  118. $url = api_get_path(WEB_CODE_PATH) . 'lp/lp_controller.php?lp_id='.$_SESSION['oLP']->get_id().'&action=add_audio&id='.$lp_item_id.'&delete_file=1&'.api_get_cidreq();
  119. $form->addElement('label', null, Display::url(get_lang('RemoveAudio'), $url, array('class' => 'btn btn-danger')));
  120. } else {
  121. $form->addElement('file', 'file');
  122. $form->addElement('hidden', 'id', $lp_item_id);
  123. $form->addButtonSave(get_lang('Save'));
  124. }
  125. $form->addElement('header', get_lang('Or'));
  126. $courseInfo = api_get_course_info();
  127. $documentTree = DocumentManager::get_document_preview(
  128. $courseInfo,
  129. false,
  130. null,
  131. api_get_session_id(),
  132. false,
  133. '',
  134. urlencode('lp_controller.php?action=add_audio&lp_id='.$_SESSION['oLP']->get_id().'&id='.$lp_item_id),
  135. false,
  136. true
  137. //$folderId = false
  138. );
  139. $page .= $recordVoiceForm;
  140. $page .= $form->returnForm();
  141. $page .= '<legend>'.get_lang('SelectAnAudioFileFromDocuments').'</legend>';
  142. $page .= $documentTree;
  143. $page .= '</div>';
  144. $page .= '</div>';
  145. $tpl->assign('content', $page);
  146. $content = $tpl->fetch('default/learnpath/lp_upload_audio.tpl');
  147. $tpl->display_one_col_template();