lp_admin_view.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This is a learning path creation and player tool in Chamilo - previously learnpath_handler.php
  5. *
  6. * @author Patrick Cool
  7. * @author Denes Nagy
  8. * @author Roan Embrechts, refactoring and code cleaning
  9. * @author Yannick Warnier <ywarnier@beeznest.org> - cleaning and update for new SCORM tool
  10. * @package chamilo.learnpath
  11. */
  12. /* INIT SECTION */
  13. $this_section = SECTION_COURSES;
  14. api_protect_course_script();
  15. /* Libraries */
  16. // The main_api.lib.php, database.lib.php and display.lib.php
  17. // libraries are included by default.
  18. include 'learnpath_functions.inc.php';
  19. //include '../resourcelinker/resourcelinker.inc.php';
  20. include 'resourcelinker.inc.php';
  21. // Rewrite the language file, sadly overwritten by resourcelinker.inc.php.
  22. $language_file = "learnpath";
  23. /* Constants and variables */
  24. $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
  25. $tbl_lp = Database::get_course_table(TABLE_LP_MAIN);
  26. $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
  27. $tbl_lp_view = Database::get_course_table(TABLE_LP_VIEW);
  28. $isStudentView = (int) $_REQUEST['isStudentView'];
  29. $learnpath_id = (int) $_REQUEST['lp_id'];
  30. $submit = $_POST['submit_button'];
  31. /*
  32. $chapter_id = $_GET['chapter_id'];
  33. $title = $_POST['title'];
  34. $description = $_POST['description'];
  35. $Submititem = $_POST['Submititem'];
  36. $action = $_REQUEST['action'];
  37. $id = (int) $_REQUEST['id'];
  38. $type = $_REQUEST['type'];
  39. $direction = $_REQUEST['direction'];
  40. $moduleid = $_REQUEST['moduleid'];
  41. $prereq = $_REQUEST['prereq'];
  42. $type = $_REQUEST['type'];
  43. */
  44. /* MAIN CODE */
  45. // Using the resource linker as a tool for adding resources to the learning path.
  46. if ($action == 'add' and $type == 'learnpathitem') {
  47. $htmlHeadXtra[] = "<script language='JavaScript' type='text/javascript'> window.location=\"../resourcelinker/resourcelinker.php?source_id=5&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no\"; </script>";
  48. }
  49. if ((!$is_allowed_to_edit) || ($isStudentView)) {
  50. error_log('New LP - User not authorized in lp_admin_view.php');
  51. header('location:lp_controller.php?action=view&lp_id='.$learnpath_id);
  52. }
  53. // From here on, we are admin because of the previous condition, so don't check anymore.
  54. $sql_query = "SELECT * FROM $tbl_lp WHERE id = $learnpath_id";
  55. $result = Database::query($sql_query);
  56. $therow = Database::fetch_array($result);
  57. //$admin_output = '';
  58. /*
  59. Course admin section
  60. - all the functions not available for students - always available in this case (page only shown to admin)
  61. */
  62. /* SHOWING THE ADMIN TOOLS */
  63. if (isset($_SESSION['gradebook'])) {
  64. $gradebook = $_SESSION['gradebook'];
  65. }
  66. if (!empty($gradebook) && $gradebook == 'view') {
  67. $interbreadcrumb[] = array (
  68. 'url' => '../gradebook/'.$_SESSION['gradebook_dest'],
  69. 'name' => get_lang('ToolGradebook')
  70. );
  71. }
  72. $interbreadcrumb[] = array('url' => 'lp_controller.php?action=list', 'name' => get_lang('_learning_path'));
  73. $interbreadcrumb[] = array('url' => api_get_self()."?action=admin_view&lp_id=$learnpath_id", "name" => stripslashes("{$therow['name']}"));
  74. // Theme calls.
  75. $show_learn_path = true;
  76. $lp_theme_css = $_SESSION['oLP']->get_theme();
  77. Display::display_header(null, 'Path');
  78. //api_display_tool_title($therow['name']);
  79. $suredel = trim(get_lang('AreYouSureToDelete'));
  80. //$suredelstep = trim(get_lang('AreYouSureToDeleteSteps'));
  81. ?>
  82. <script type='text/javascript'>
  83. /* <![CDATA[ */
  84. function stripslashes(str) {
  85. str=str.replace(/\\'/g,'\'');
  86. str=str.replace(/\\"/g,'"');
  87. str=str.replace(/\\\\/g,'\\');
  88. str=str.replace(/\\0/g,'\0');
  89. return str;
  90. }
  91. function confirmation(name)
  92. {
  93. name=stripslashes(name);
  94. if (confirm("<?php echo $suredel; ?> " + name + " ?"))
  95. {
  96. return true;
  97. }
  98. else
  99. {
  100. return false;
  101. }
  102. }
  103. </script>
  104. <?php
  105. /* DISPLAY SECTION */
  106. switch ($_GET['action']) {
  107. case 'edit_item':
  108. if (isset($is_success) && $is_success === true) {
  109. Display::display_confirmation_message(get_lang('_learnpath_item_edited'));
  110. } else {
  111. echo $_SESSION['oLP']->display_edit_item($_GET['id']);
  112. }
  113. break;
  114. case 'delete_item':
  115. if (isset($is_success) && $is_success === true) {
  116. Display::display_confirmation_message(get_lang('_learnpath_item_deleted'));
  117. }
  118. break;
  119. }
  120. // POST action handling (uploading mp3, deleting mp3)
  121. if (isset($_POST['save_audio'])) {
  122. // Deleting the audio fragments.
  123. foreach ($_POST as $key => $value) {
  124. if (substr($key, 0, 9) == 'removemp3') {
  125. $lp_items_to_remove_audio[] = str_ireplace('removemp3', '', $key);
  126. // Removing the audio from the learning path item.
  127. $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
  128. $in = implode(',', $lp_items_to_remove_audio);
  129. }
  130. }
  131. if (count($lp_items_to_remove_audio)>0) {
  132. $sql = "UPDATE $tbl_lp_item SET audio = '' WHERE id IN (".$in.")";
  133. $result = Database::query($sql);
  134. }
  135. // Uploading the audio files.
  136. foreach ($_FILES as $key => $value) {
  137. if (substr($key, 0, 7) == 'mp3file' AND !empty($_FILES[$key]['tmp_name'])) {
  138. // The id of the learning path item.
  139. $lp_item_id = str_ireplace('mp3file', '', $key);
  140. // Create the audio folder if it does not exist yet.
  141. global $_course;
  142. $filepath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document/';
  143. if (!is_dir($filepath.'audio')) {
  144. mkdir($filepath.'audio', api_get_permissions_for_new_directories());
  145. $audio_id = add_document($_course, '/audio', 'folder', 0, 'audio');
  146. api_item_property_update($_course, TOOL_DOCUMENT, $audio_id, 'FolderCreated', api_get_user_id(), null, null, null, null, api_get_session_id());
  147. }
  148. // Check if file already exits into document/audio/
  149. $file_name = $_FILES[$key]['name'];
  150. $file_name = stripslashes($file_name);
  151. // Add extension to files without one (if possible).
  152. $file_name = add_ext_on_mime($file_name, $_FILES[$key]['type']);
  153. $clean_name = replace_dangerous_char($file_name);
  154. // No "dangerous" files.
  155. $clean_name = disable_dangerous_file($clean_name);
  156. $check_file_path = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document/audio/'.$clean_name;
  157. // If the file exists we generate a new name.
  158. if (file_exists($check_file_path)) {
  159. $filename_components = explode('.', $clean_name);
  160. // Gettting the extension of the file.
  161. $file_extension = $filename_components[count($filename_components) - 1];
  162. // Adding something random to prevent overwriting.
  163. $filename_components[count($filename_components) - 1] = time();
  164. // Reconstructing the new filename.
  165. $clean_name = implode($filename_components) .'.'.$file_extension;
  166. // Using the new name in the $_FILES superglobal.
  167. $_FILES[$key]['name'] = $clean_name;
  168. }
  169. // Upload the file in the documents tool.
  170. include_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
  171. $file_path = handle_uploaded_document($_course, $_FILES[$key], api_get_path(SYS_COURSE_PATH).$_course['path'].'/document','/audio', api_get_user_id(), '', '', '', '', '', false);
  172. // Getting the filename only.
  173. $file_components = explode('/', $file_path);
  174. $file = $file_components[count($file_components) - 1];
  175. // Store the mp3 file in the lp_item table.
  176. $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
  177. $sql_insert_audio = "UPDATE $tbl_lp_item SET audio = '".Database::escape_string($file)."' WHERE id = '".Database::escape_string($lp_item_id)."'";
  178. Database::query($sql_insert_audio);
  179. }
  180. }
  181. Display::display_confirmation_message(get_lang('ChangesStored'));
  182. }
  183. echo $_SESSION['oLP']->overview();
  184. /* FOOTER */
  185. Display::display_footer();