lp_add_audio.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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 'chapter':
  43. $interbreadcrumb[]= array('url' => 'lp_controller.php?action=add_item&type=step&lp_id='.$_SESSION['oLP']->get_id(), 'name' => get_lang('NewStep'));
  44. $interbreadcrumb[]= array('url' => '#', 'name' => get_lang('NewChapter'));
  45. break;
  46. case 'document':
  47. $interbreadcrumb[]= array('url' => 'lp_controller.php?action=add_item&type=step&lp_id='.$_SESSION['oLP']->get_id(), 'name' => get_lang('NewStep'));
  48. break;
  49. default:
  50. $interbreadcrumb[]= array('url' => '#', 'name' => get_lang('NewStep'));
  51. break;
  52. }
  53. if ($action == 'add_item' && $type == 'document') {
  54. $interbreadcrumb[]= array ('url' => '#', 'name' => get_lang('NewDocumentCreated'));
  55. }
  56. // Theme calls.
  57. $show_learn_path = true;
  58. $lp_item_id = isset($_GET['id']) ? intval($_GET['id']) : null;
  59. if (empty($lp_item_id)) {
  60. api_not_allowed();
  61. }
  62. $courseInfo = api_get_course_info();
  63. $lp_item = new learnpathItem($lp_item_id);
  64. $form = new FormValidator(
  65. 'add_audio',
  66. 'post',
  67. api_get_self() . '?action=add_audio&id=' . $lp_item_id . '&' . api_get_cidreq().'&lp_id='.$learnpath_id,
  68. null,
  69. array('enctype' => 'multipart/form-data')
  70. );
  71. $suredel = trim(get_lang('AreYouSureToDeleteJS'));
  72. $lpPathInfo = $_SESSION['oLP']->generate_lp_folder(api_get_course_info());
  73. $file = null;
  74. if (isset($lp_item->audio) && !empty($lp_item->audio)) {
  75. $file = api_get_path(SYS_COURSE_PATH).$courseInfo['path'].'/document/audio/'.$lp_item->audio;
  76. $urlFile = api_get_path(WEB_COURSE_PATH).$courseInfo['path'].'/document/audio/'.$lp_item->audio.'?'.api_get_cidreq();
  77. if (!file_exists($file)) {
  78. $file = api_get_path(SYS_COURSE_PATH).$courseInfo['path'].'/document'.$lpPathInfo['dir'].$lp_item->audio;
  79. $urlFile = api_get_path(WEB_COURSE_PATH).$courseInfo['path'].'/document'.$lpPathInfo['dir'].$lp_item->audio.'?'.api_get_cidreq();
  80. }
  81. }
  82. $page = $_SESSION['oLP']->build_action_menu(true);
  83. $page .= '<div class="row" style="overflow:hidden">';
  84. $page .= '<div id="lp_sidebar" class="col-md-4">';
  85. $page .= $_SESSION['oLP']->return_new_tree(null, true);
  86. // Show the template list.
  87. $page .= '</div>';
  88. $recordVoiceForm = Display::page_subheader(get_lang('RecordYourVoice'));
  89. $page .= '<div id="doc_form" class="col-md-8">';
  90. $tpl = new Template(null);
  91. $tpl->assign('unique_file_id', api_get_unique_id());
  92. $tpl->assign('course_code', api_get_course_id());
  93. $tpl->assign('php_session_id', session_id());
  94. $tpl->assign('filename', $lp_item->get_title().'_nano.wav');
  95. $tpl->assign('enable_nanogong', api_get_setting('enable_nanogong') == 'true' ? 1 : 0);
  96. $tpl->assign('enable_wami', api_get_setting('enable_wami_record') == 'true' ? 1 : 0);
  97. $tpl->assign('cur_dir_path', '/audio');
  98. $tpl->assign('lp_item_id', $lp_item_id);
  99. $tpl->assign('lp_dir', api_remove_trailing_slash($lpPathInfo['dir']));
  100. $recordVoiceForm .= $tpl->fetch('default/learnpath/record_voice.tpl');
  101. $form->addElement('header', get_lang('Or'));
  102. $form->addElement('header', get_lang('AudioFile'));
  103. $form->addElement('html', sprintf(get_lang('AudioFileForItemX'), $lp_item->get_title()));
  104. if (!empty($file)) {
  105. $audioPlayer = '<div id="preview">'.
  106. Display::getMediaPlayer($file, array('url' => $urlFile)).
  107. "</div>";
  108. $form->addElement('label', get_lang('Listen'), $audioPlayer);
  109. $url = api_get_path(WEB_CODE_PATH).'newscorm/lp_controller.php?lp_id='.$_SESSION['oLP']->get_id().'&action=add_audio&id='.$lp_item_id.'&delete_file=1&'.api_get_cidreq();
  110. $form->addElement('label', null, Display::url(get_lang('RemoveAudio'), $url, array('class' => 'btn btn-danger')));
  111. } else {
  112. $form->addElement('file', 'file');
  113. $form->addElement('hidden', 'id', $lp_item_id);
  114. $form->addButtonSave(get_lang('Save'));
  115. }
  116. $form->addElement('header', get_lang('Or'));
  117. $courseInfo = api_get_course_info();
  118. $documentTree = DocumentManager::get_document_preview(
  119. $courseInfo,
  120. false,
  121. null,
  122. api_get_session_id(),
  123. false,
  124. '',
  125. urlencode('lp_controller.php?action=add_audio&lp_id='.$_SESSION['oLP']->get_id().'&id='.$lp_item_id),
  126. false,
  127. true
  128. //$folderId = false
  129. );
  130. $page .= $recordVoiceForm;
  131. $page .= $form->return_form();
  132. $page .= '<legend>'.get_lang('SelectAnAudioFileFromDocuments').'</legend>';
  133. $page .= $documentTree;
  134. $page .= '</div>';
  135. $page .= '</div>';
  136. $tpl->assign('content', $page);
  137. $content = $tpl->fetch('default/learnpath/lp_upload_audio.tpl');
  138. $tpl->display_one_col_template();