lp_add_audio.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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. $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
  12. $isStudentView = isset($_REQUEST['isStudentView']) ? (int)$_REQUEST['isStudentView'] : null;
  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_item.php');
  19. header('location:lp_controller.php?action=view&lp_id='.$learnpath_id);
  20. exit;
  21. }
  22. /* SHOWING THE ADMIN TOOLS */
  23. if (api_is_in_gradebook()) {
  24. $interbreadcrumb[]= array(
  25. 'url' => api_get_path(WEB_CODE_PATH).'gradebook/index.php?'.api_get_cidreq(),
  26. 'name' => get_lang('ToolGradebook')
  27. );
  28. }
  29. $learnPath = learnpath::getCurrentLpFromSession();
  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' => $learnPath->get_name(),
  37. );
  38. switch ($type) {
  39. case 'chapter':
  40. $interbreadcrumb[] = array(
  41. 'url' => 'lp_controller.php?action=add_item&type=step&lp_id='.$learnPath->get_id(),
  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='.$learnPath->get_id(),
  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 = $learnPath->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 = $learnPath->build_action_menu(true);
  86. $page .= '<div class="row" style="overflow:hidden">';
  87. $page .= '<div id="lp_sidebar" class="col-md-4">';
  88. $page .= $learnPath->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. $tpl = \Chamilo\CoreBundle\Framework\Container::getTwig();
  94. $tpl->addGlobal('unique_file_id', api_get_unique_id());
  95. $tpl->addGlobal('course_code', api_get_course_id());
  96. $tpl->addGlobal('php_session_id', session_id());
  97. $tpl->addGlobal('filename', $lp_item->get_title().'_nano.wav');
  98. $tpl->addGlobal(
  99. 'enable_nanogong',
  100. api_get_setting('document.enable_nanogong') == 'true' ? 1 : 0
  101. );
  102. $tpl->addGlobal(
  103. 'enable_wami',
  104. api_get_setting('document.enable_wami_record') == 'true' ? 1 : 0
  105. );
  106. $tpl->addGlobal('cur_dir_path', '/audio');
  107. $tpl->addGlobal('lp_item_id', $lp_item_id);
  108. $tpl->addGlobal('lp_dir', api_remove_trailing_slash($lpPathInfo['dir']));
  109. $recordVoiceForm .= $tpl->render(
  110. '@template_style/learnpath/record_voice.html.twig'
  111. );
  112. $form->addElement('header', get_lang('Or'));
  113. $form->addElement('header', get_lang('AudioFile'));
  114. $form->addElement('html', sprintf(get_lang('AudioFileForItemX'), $lp_item->get_title()));
  115. if (!empty($file)) {
  116. $audioPlayer = '<div id="preview">'.
  117. Display::getMediaPlayer($file, array('url' => $urlFile)).
  118. "</div>";
  119. $form->addElement('label', get_lang('Listen'), $audioPlayer);
  120. $url = api_get_path(
  121. WEB_CODE_PATH
  122. ).'newscorm/lp_controller.php?lp_id='.$learnPath->get_id(
  123. ).'&action=add_audio&id='.$lp_item_id.'&delete_file=1&'.api_get_cidreq(
  124. );
  125. $form->addElement('label', null, Display::url(get_lang('RemoveAudio'), $url, array('class' => 'btn btn-danger')));
  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(
  141. 'lp_controller.php?action=add_audio&lp_id='.$learnPath->get_id(
  142. ).'&id='.$lp_item_id
  143. ),
  144. false,
  145. true
  146. //$folderId = false
  147. );
  148. $page .= $recordVoiceForm;
  149. $page .= $form->returnForm();
  150. $page .= '<legend>'.get_lang('SelectAnAudioFileFromDocuments').'</legend>';
  151. $page .= $documentTree;
  152. $page .= '</div>';
  153. $page .= '</div>';
  154. echo $page;