lp_add_audio.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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. error_log('New LP - User not authorized in lp_add_audio.php');
  21. header('location:lp_controller.php?action=view&lp_id='.$learnpath_id);
  22. exit;
  23. }
  24. /** @var learnpath $lp */
  25. $lp = Session::read('oLP');
  26. if (api_is_in_gradebook()) {
  27. $interbreadcrumb[] = [
  28. 'url' => Category::getUrl(),
  29. 'name' => get_lang('ToolGradebook'),
  30. ];
  31. }
  32. $interbreadcrumb[] = [
  33. 'url' => 'lp_controller.php?action=list&'.api_get_cidreq(),
  34. 'name' => get_lang('LearningPaths'),
  35. ];
  36. $interbreadcrumb[] = [
  37. 'url' => api_get_self()."?action=build&lp_id=$learnpath_id&".api_get_cidreq(),
  38. 'name' => $lp->get_name(),
  39. ];
  40. switch ($type) {
  41. case 'dir':
  42. $interbreadcrumb[] = [
  43. 'url' => 'lp_controller.php?action=add_item&type=step&lp_id='.$lp->get_id().'&'.api_get_cidreq(),
  44. 'name' => get_lang('NewStep'),
  45. ];
  46. $interbreadcrumb[] = ['url' => '#', 'name' => get_lang('NewChapter')];
  47. break;
  48. case 'document':
  49. $interbreadcrumb[] = [
  50. 'url' => 'lp_controller.php?action=add_item&type=step&lp_id='.$lp->get_id().'&'.api_get_cidreq(),
  51. 'name' => get_lang('NewStep'),
  52. ];
  53. break;
  54. default:
  55. $interbreadcrumb[] = ['url' => '#', 'name' => get_lang('NewStep')];
  56. break;
  57. }
  58. if ($action == 'add_item' && $type == 'document') {
  59. $interbreadcrumb[] = ['url' => '#', 'name' => get_lang('NewDocumentCreated')];
  60. }
  61. // Theme calls.
  62. $show_learn_path = true;
  63. $lp_item_id = isset($_GET['id']) ? intval($_GET['id']) : null;
  64. if (empty($lp_item_id)) {
  65. api_not_allowed();
  66. }
  67. $courseInfo = api_get_course_info();
  68. $lp_item = new learnpathItem($lp_item_id);
  69. $form = new FormValidator(
  70. 'add_audio',
  71. 'post',
  72. api_get_self().'?action=add_audio&id='.$lp_item_id.'&'.api_get_cidreq().'&lp_id='.$learnpath_id,
  73. null,
  74. ['enctype' => 'multipart/form-data']
  75. );
  76. $suredel = trim(get_lang('AreYouSureToDeleteJS'));
  77. $lpPathInfo = $lp->generate_lp_folder(api_get_course_info());
  78. $file = null;
  79. if (isset($lp_item->audio) && !empty($lp_item->audio)) {
  80. $file = api_get_path(SYS_COURSE_PATH).$courseInfo['path'].'/document/audio/'.$lp_item->audio;
  81. $urlFile = api_get_path(WEB_COURSE_PATH).$courseInfo['path'].'/document/audio/'.$lp_item->audio.'?'.api_get_cidreq();
  82. if (!file_exists($file)) {
  83. $file = api_get_path(SYS_COURSE_PATH).$courseInfo['path'].'/document'.$lpPathInfo['dir'].'/'.$lp_item->audio;
  84. $urlFile = api_get_path(WEB_COURSE_PATH).$courseInfo['path'].'/document'.$lpPathInfo['dir'].'/'.$lp_item->audio.'?'.api_get_cidreq();
  85. }
  86. }
  87. $page = $lp->build_action_menu(true);
  88. $page .= '<div class="row" style="overflow:hidden">';
  89. $page .= '<div id="lp_sidebar" class="col-md-4">';
  90. $page .= $lp->return_new_tree(null, true);
  91. // Show the template list.
  92. $page .= '</div>';
  93. $recordVoiceForm = Display::page_subheader(get_lang('RecordYourVoice'));
  94. $page .= '<div id="doc_form" class="col-md-8">';
  95. $htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_JS_PATH).'rtc/RecordRTC.js"></script>';
  96. $htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'wami-recorder/recorder.js"></script>';
  97. $htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'wami-recorder/gui.js"></script>';
  98. $htmlHeadXtra[] = '<script type="text/javascript" src="'.api_get_path(WEB_LIBRARY_PATH).'swfobject/swfobject.js"></script>';
  99. $tpl = new Template(null);
  100. $tpl->assign('unique_file_id', api_get_unique_id());
  101. $tpl->assign('course_code', api_get_course_id());
  102. $tpl->assign('filename', $lp_item->get_title().'_nano.wav');
  103. $tpl->assign('enable_record_audio', api_get_setting('enable_record_audio') === 'true');
  104. $tpl->assign('cur_dir_path', '/audio');
  105. $tpl->assign('lp_item_id', $lp_item_id);
  106. $tpl->assign('lp_dir', api_remove_trailing_slash($lpPathInfo['dir']));
  107. $template = $tpl->get_template('learnpath/record_voice.tpl');
  108. $recordVoiceForm .= $tpl->fetch($template);
  109. $form->addElement('header', get_lang('Or'));
  110. $form->addElement('header', 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. $form->addElement('header', get_lang('Or'));
  133. $courseInfo = api_get_course_info();
  134. $documentTree = DocumentManager::get_document_preview(
  135. $courseInfo,
  136. false,
  137. null,
  138. api_get_session_id(),
  139. false,
  140. '',
  141. api_get_path(WEB_CODE_PATH).'lp/lp_controller.php?action=add_audio&lp_id='.$lp->get_id().'&id='.$lp_item_id,
  142. false,
  143. true
  144. //$folderId = false
  145. );
  146. $page .= $recordVoiceForm;
  147. $page .= $form->returnForm();
  148. $page .= '<legend>'.get_lang('SelectAnAudioFileFromDocuments').'</legend>';
  149. $page .= $documentTree;
  150. $page .= '</div>';
  151. $page .= '</div>';
  152. $tpl->assign('content', $page);
  153. $template = $tpl->get_template('learnpath/lp_upload_audio.tpl');
  154. $content = $tpl->fetch($template);
  155. $tpl->display_one_col_template();