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