lp_add_audio.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use ChamiloSession as Session;
  4. /**
  5. * This is a learning path creation and player tool in Chamilo - previously.
  6. *
  7. * @author Julio Montoya - Improving the list of templates
  8. *
  9. * @package chamilo.learnpath
  10. */
  11. $this_section = SECTION_COURSES;
  12. api_protect_course_script();
  13. $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
  14. $isStudentView = api_is_student_view_active();
  15. $learnpath_id = (int) $_REQUEST['lp_id'];
  16. $submit = isset($_POST['submit_button']) ? $_POST['submit_button'] : null;
  17. $type = isset($_GET['type']) ? $_GET['type'] : null;
  18. $action = isset($_GET['action']) ? $_GET['action'] : null;
  19. if (!$is_allowed_to_edit || $isStudentView) {
  20. header('location:lp_controller.php?action=view&lp_id='.$learnpath_id);
  21. exit;
  22. }
  23. /** @var learnpath $lp */
  24. $lp = Session::read('oLP');
  25. if (api_is_in_gradebook()) {
  26. $interbreadcrumb[] = [
  27. 'url' => Category::getUrl(),
  28. 'name' => get_lang('ToolGradebook'),
  29. ];
  30. }
  31. $interbreadcrumb[] = [
  32. 'url' => 'lp_controller.php?action=list&'.api_get_cidreq(),
  33. 'name' => get_lang('LearningPaths'),
  34. ];
  35. $interbreadcrumb[] = [
  36. 'url' => api_get_self()."?action=build&lp_id=$learnpath_id&".api_get_cidreq(),
  37. 'name' => $lp->getNameNoTags(),
  38. ];
  39. switch ($type) {
  40. case 'dir':
  41. $interbreadcrumb[] = [
  42. 'url' => 'lp_controller.php?action=add_item&type=step&lp_id='.$lp->get_id().'&'.api_get_cidreq(),
  43. 'name' => get_lang('NewStep'),
  44. ];
  45. $interbreadcrumb[] = ['url' => '#', 'name' => get_lang('NewChapter')];
  46. break;
  47. case 'document':
  48. $interbreadcrumb[] = [
  49. 'url' => 'lp_controller.php?action=add_item&type=step&lp_id='.$lp->get_id().'&'.api_get_cidreq(),
  50. 'name' => get_lang('NewStep'),
  51. ];
  52. break;
  53. default:
  54. $interbreadcrumb[] = ['url' => '#', 'name' => get_lang('NewStep')];
  55. break;
  56. }
  57. if ($action == 'add_item' && $type == 'document') {
  58. $interbreadcrumb[] = ['url' => '#', 'name' => get_lang('NewDocumentCreated')];
  59. }
  60. // Theme calls.
  61. $show_learn_path = true;
  62. $lp_item_id = isset($_GET['id']) ? intval($_GET['id']) : null;
  63. if (empty($lp_item_id)) {
  64. api_not_allowed();
  65. }
  66. $courseInfo = api_get_course_info();
  67. $lp_item = new learnpathItem($lp_item_id);
  68. $form = new FormValidator(
  69. 'add_audio',
  70. 'post',
  71. api_get_self().'?action=add_audio&id='.$lp_item_id.'&'.api_get_cidreq().'&lp_id='.$learnpath_id,
  72. null,
  73. ['enctype' => 'multipart/form-data']
  74. );
  75. $suredel = trim(get_lang('AreYouSureToDeleteJS'));
  76. $lpPathInfo = $lp->generate_lp_folder(api_get_course_info());
  77. DocumentManager::createDefaultAudioFolder($courseInfo);
  78. $audioFolderId = DocumentManager::get_document_id($courseInfo, '/audio');
  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 = $lp->build_action_menu(true);
  89. $page .= '<div class="row" style="overflow:hidden">';
  90. $page .= '<div id="lp_sidebar" class="col-md-4">';
  91. $page .= $lp->return_new_tree(null, true);
  92. // Show the template list.
  93. $page .= '</div>';
  94. $recordVoiceForm = '<h3 class="page-header">'.get_lang('RecordYourVoice').'</h3>';
  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('filename', $lp_item->get_title().'_nano.wav');
  104. $tpl->assign('enable_record_audio', api_get_setting('enable_record_audio') === 'true');
  105. $tpl->assign('cur_dir_path', '/audio');
  106. $tpl->assign('lp_item_id', $lp_item_id);
  107. $tpl->assign('lp_dir', api_remove_trailing_slash($lpPathInfo['dir']));
  108. $template = $tpl->get_template('learnpath/record_voice.tpl');
  109. $recordVoiceForm .= $tpl->fetch($template);
  110. $form->addElement('header', '<small class="text-muted">'.get_lang('Or').'</small> '.get_lang('AudioFile'));
  111. $form->addLabel(null, sprintf(get_lang('AudioFileForItemX'), $lp_item->get_title()));
  112. if (!empty($file)) {
  113. $audioPlayer = '<div id="preview">'.
  114. Display::getMediaPlayer($file, ['url' => $urlFile]).
  115. "</div>";
  116. $form->addElement('label', get_lang('Listen'), $audioPlayer);
  117. $url = api_get_path(WEB_CODE_PATH).'lp/lp_controller.php?lp_id='.$lp->get_id().'&action=add_audio&id='.$lp_item_id.'&delete_file=1&'.api_get_cidreq();
  118. $form->addElement(
  119. 'label',
  120. null,
  121. Display::url(
  122. get_lang('RemoveAudio'),
  123. $url,
  124. ['class' => 'btn btn-danger']
  125. )
  126. );
  127. } else {
  128. $form->addElement('file', 'file');
  129. $form->addElement('hidden', 'id', $lp_item_id);
  130. $form->addButtonSave(get_lang('Save'));
  131. }
  132. $courseInfo = api_get_course_info();
  133. $documentTree = DocumentManager::get_document_preview(
  134. $courseInfo,
  135. $lp->get_id(),
  136. null,
  137. api_get_session_id(),
  138. false,
  139. '',
  140. api_get_path(WEB_CODE_PATH).'lp/lp_controller.php?action=add_audio&lp_id='.$lp->get_id().'&id='.$lp_item_id,
  141. false,
  142. true,
  143. $audioFolderId
  144. );
  145. $page .= $recordVoiceForm;
  146. $page .= '<br>';
  147. $page .= $form->returnForm();
  148. $page .= '<h3 class="page-header"><small>'.get_lang('Or').'</small> '.get_lang('SelectAnAudioFileFromDocuments').'</h3>';
  149. $page .= '<ul class="lp_resource">';
  150. $page .= '<li class="doc_folder" style="margin-left: 36px;">'.get_lang('Audio').'</li>';
  151. $page .= '<li class="doc_folder">';
  152. $page .= '<ul class="lp_resource">'.$documentTree.'</ul>';
  153. $page .= '</div>';
  154. $page .= '</ul>';
  155. $page .= '</div>';
  156. $page .= '</div>';
  157. $tpl->assign('content', $page);
  158. $tpl->display_one_col_template();