lp_add_audio.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. /**
  9. * INIT SECTION
  10. */
  11. $this_section = SECTION_COURSES;
  12. api_protect_course_script();
  13. require_once 'learnpath_functions.inc.php';
  14. require_once 'resourcelinker.inc.php';
  15. $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
  16. $isStudentView = (int) $_REQUEST['isStudentView'];
  17. $learnpath_id = (int) $_REQUEST['lp_id'];
  18. $submit = $_POST['submit_button'];
  19. $type = isset($_GET['type']) ? $_GET['type'] : null;
  20. $action = isset($_GET['action']) ? $_GET['action'] : null;
  21. // Using the resource linker as a tool for adding resources to the learning path.
  22. if ($action == 'add' && $type == 'learnpathitem') {
  23. $htmlHeadXtra[] = "<script>
  24. window.location=\"../resourcelinker/resourcelinker.php?source_id=5&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no\";
  25. </script>";
  26. }
  27. if ((!$is_allowed_to_edit) || ($isStudentView)) {
  28. error_log('New LP - User not authorized in lp_add_item.php');
  29. header('location:lp_controller.php?action=view&lp_id='.$learnpath_id);
  30. exit;
  31. }
  32. /* SHOWING THE ADMIN TOOLS */
  33. if (isset($_SESSION['gradebook'])) {
  34. $gradebook = $_SESSION['gradebook'];
  35. }
  36. if (!empty($gradebook) && $gradebook == 'view') {
  37. $interbreadcrumb[] = array (
  38. 'url' => '../gradebook/'.$_SESSION['gradebook_dest'],
  39. 'name' => get_lang('ToolGradebook')
  40. );
  41. }
  42. $interbreadcrumb[] = array('url' => 'lp_controller.php?action=list', 'name' => get_lang('LearningPaths'));
  43. $interbreadcrumb[] = array('url' => api_get_self()."?action=build&lp_id=$learnpath_id", 'name' => $_SESSION['oLP']->get_name());
  44. switch ($type) {
  45. case 'chapter':
  46. $interbreadcrumb[]= array ('url' => 'lp_controller.php?action=add_item&type=step&lp_id='.$_SESSION['oLP']->get_id(), 'name' => get_lang('NewStep'));
  47. $interbreadcrumb[]= array ('url' => '#', 'name' => get_lang('NewChapter'));
  48. break;
  49. case 'document':
  50. $interbreadcrumb[]= array ('url' => 'lp_controller.php?action=add_item&type=step&lp_id='.$_SESSION['oLP']->get_id(), 'name' => get_lang('NewStep'));
  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. $lp_item = new learnpathItem($lp_item_id);
  66. /** @var Template $tpl */
  67. $tpl = $app['template'];
  68. $form = new FormValidator('add_audio', 'post', api_get_self().'?action=add_audio&id='.$lp_item_id, null, array('enctype' => 'multipart/form-data'));
  69. $suredel = trim(get_lang('AreYouSureToDelete'));
  70. $lpPathInfo = $_SESSION['oLP']->generate_lp_folder(api_get_course_info());
  71. $file = null;
  72. if (isset($lp_item->audio) && !empty($lp_item->audio)) {
  73. $file = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document/audio/'.$lp_item->audio;
  74. $urlFile = api_get_path(WEB_COURSE_PATH).$_course['path'].'/document/audio/'.$lp_item->audio;
  75. if (!file_exists($file)) {
  76. $file = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document'.$lpPathInfo['dir'].$lp_item->audio;
  77. $urlFile = api_get_path(WEB_COURSE_PATH).$_course['path'].'/document'.$lpPathInfo['dir'].$lp_item->audio;
  78. }
  79. }
  80. $page = $_SESSION['oLP']->build_action_menu(true);
  81. $page .= '<div class="row" style="overflow:hidden">';
  82. $page .= '<div id="lp_sidebar" class="col-md-4">';
  83. $page .= $_SESSION['oLP']->return_new_tree(null, true);
  84. // Show the template list.
  85. $page .= '</div>';
  86. $page .= '<div id="doc_form" class="col-md-8">';
  87. $form->addElement('header', get_lang('RecordYourVoice'));
  88. $tpl->assign('unique_file_id', api_get_unique_id());
  89. $tpl->assign('course_code', api_get_course_id());
  90. $tpl->assign('php_session_id', session_id());
  91. $tpl->assign('filename', $lp_item->get_title().'_nano.wav');
  92. $tpl->assign('enable_nanogong', api_get_setting('enable_nanogong') == 'true' ? 1 : 0);
  93. $tpl->assign('enable_wami', api_get_setting('enable_wami_record') == 'true' ? 1 : 0);
  94. //$tpl->assign('cur_dir_path', api_remove_trailing_slash($lpPathInfo['dir']));
  95. $tpl->assign('cur_dir_path', '/audio');
  96. $tpl->assign('lp_item_id', $lp_item_id);
  97. $tpl->assign('lp_dir', api_remove_trailing_slash($lpPathInfo['dir']));
  98. $voiceContent = $tpl->fetch('default/learnpath/record_voice.tpl');
  99. $form->addElement('html', $voiceContent);
  100. $form->addElement('header', get_lang('UplUpload'));
  101. $form->addElement('html', $lp_item->get_title());
  102. $form->addElement('file', 'file', get_lang('AudioFile'), 'style="width: 250px"');
  103. if (!empty($file)) {
  104. $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();
  105. $form->addElement('label', null, Display::url(get_lang('RemoveAudio'), $url, array('class' => 'btn btn-danger')));
  106. }
  107. $form->addElement('hidden', 'id', $lp_item_id);
  108. if (!empty($file)) {
  109. $audioPlayer = '<div id="preview">'.Display::getMediaPlayer($file, array('url' => $urlFile))."</div>";
  110. $form->addElement('label', get_lang('Preview'), $audioPlayer);
  111. }
  112. $form->addElement('button', 'submit', get_lang('Edit'));
  113. $course_info = api_get_course_info();
  114. $document_tree = DocumentManager::get_document_preview(
  115. $course_info,
  116. null,
  117. null,
  118. 0,
  119. false,
  120. '/audio',
  121. 'lp_controller.php?action=add_audio&id='.$lp_item_id
  122. );
  123. $page .= $form->return_form();
  124. $page .= '<legend>'.get_lang('SelectAnAudioFileFromDocuments').'</legend>';
  125. $page .= $document_tree;
  126. $page .= '</div>';
  127. $page .= '</div>';
  128. $tpl->assign('content', $page);