lp_add_audio.php 6.3 KB

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