lp_admin_view.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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('LearningPaths'));
  73. $interbreadcrumb[] = array('url' => api_get_self()."?action=build&lp_id=$learnpath_id", "name" => stripslashes("{$therow['name']}"));
  74. if (isset($_REQUEST['updateaudio'])) {
  75. $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('UpdateAllAudioFragments'));
  76. } else {
  77. $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('BasicOverview'));
  78. }
  79. // Theme calls.
  80. $show_learn_path = true;
  81. $lp_theme_css = $_SESSION['oLP']->get_theme();
  82. Display::display_header(null, 'Path');
  83. //api_display_tool_title($therow['name']);
  84. $suredel = trim(get_lang('AreYouSureToDelete'));
  85. //$suredelstep = trim(get_lang('AreYouSureToDeleteSteps'));
  86. ?>
  87. <script type='text/javascript'>
  88. /* <![CDATA[ */
  89. function stripslashes(str) {
  90. str=str.replace(/\\'/g,'\'');
  91. str=str.replace(/\\"/g,'"');
  92. str=str.replace(/\\\\/g,'\\');
  93. str=str.replace(/\\0/g,'\0');
  94. return str;
  95. }
  96. function confirmation(name)
  97. {
  98. name=stripslashes(name);
  99. if (confirm("<?php echo $suredel; ?> " + name + " ?"))
  100. {
  101. return true;
  102. }
  103. else
  104. {
  105. return false;
  106. }
  107. }
  108. </script>
  109. <?php
  110. /* DISPLAY SECTION */
  111. switch ($_GET['action']) {
  112. case 'edit_item':
  113. if (isset($is_success) && $is_success === true) {
  114. Display::display_confirmation_message(get_lang('_learnpath_item_edited'));
  115. } else {
  116. echo $_SESSION['oLP']->display_edit_item($_GET['id']);
  117. }
  118. break;
  119. case 'delete_item':
  120. if (isset($is_success) && $is_success === true) {
  121. Display::display_confirmation_message(get_lang('_learnpath_item_deleted'));
  122. }
  123. break;
  124. }
  125. // POST action handling (uploading mp3, deleting mp3)
  126. if (isset($_POST['save_audio'])) {
  127. //Updating the lp.modified_on
  128. $_SESSION['oLP']->set_modified_on();
  129. // Deleting the audio fragments.
  130. foreach ($_POST as $key => $value) {
  131. if (substr($key, 0, 9) == 'removemp3') {
  132. $lp_items_to_remove_audio[] = str_ireplace('removemp3', '', $key);
  133. // Removing the audio from the learning path item.
  134. $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
  135. $in = implode(',', $lp_items_to_remove_audio);
  136. }
  137. }
  138. if (count($lp_items_to_remove_audio)>0) {
  139. $sql = "UPDATE $tbl_lp_item SET audio = '' WHERE id IN (".$in.")";
  140. $result = Database::query($sql);
  141. }
  142. // Uploading the audio files.
  143. foreach ($_FILES as $key => $value) {
  144. if (substr($key, 0, 7) == 'mp3file' AND !empty($_FILES[$key]['tmp_name'])) {
  145. // The id of the learning path item.
  146. $lp_item_id = str_ireplace('mp3file', '', $key);
  147. // Create the audio folder if it does not exist yet.
  148. global $_course;
  149. $filepath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document/';
  150. if (!is_dir($filepath.'audio')) {
  151. mkdir($filepath.'audio', api_get_permissions_for_new_directories());
  152. $audio_id = add_document($_course, '/audio', 'folder', 0, 'audio');
  153. api_item_property_update($_course, TOOL_DOCUMENT, $audio_id, 'FolderCreated', api_get_user_id(), null, null, null, null, api_get_session_id());
  154. }
  155. // Check if file already exits into document/audio/
  156. $file_name = $_FILES[$key]['name'];
  157. $file_name = stripslashes($file_name);
  158. // Add extension to files without one (if possible).
  159. $file_name = add_ext_on_mime($file_name, $_FILES[$key]['type']);
  160. $clean_name = replace_dangerous_char($file_name);
  161. // No "dangerous" files.
  162. $clean_name = disable_dangerous_file($clean_name);
  163. $check_file_path = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document/audio/'.$clean_name;
  164. // If the file exists we generate a new name.
  165. if (file_exists($check_file_path)) {
  166. $filename_components = explode('.', $clean_name);
  167. // Gettting the extension of the file.
  168. $file_extension = $filename_components[count($filename_components) - 1];
  169. // Adding something random to prevent overwriting.
  170. $filename_components[count($filename_components) - 1] = time();
  171. // Reconstructing the new filename.
  172. $clean_name = implode($filename_components) .'.'.$file_extension;
  173. // Using the new name in the $_FILES superglobal.
  174. $_FILES[$key]['name'] = $clean_name;
  175. }
  176. // Upload the file in the documents tool.
  177. include_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
  178. $file_path = handle_uploaded_document($_course, $_FILES[$key], api_get_path(SYS_COURSE_PATH).$_course['path'].'/document','/audio', api_get_user_id(), '', '', '', '', '', false);
  179. // Getting the filename only.
  180. $file_components = explode('/', $file_path);
  181. $file = $file_components[count($file_components) - 1];
  182. // Store the mp3 file in the lp_item table.
  183. $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
  184. $sql_insert_audio = "UPDATE $tbl_lp_item SET audio = '".Database::escape_string($file)."' WHERE id = '".Database::escape_string($lp_item_id)."'";
  185. Database::query($sql_insert_audio);
  186. }
  187. }
  188. Display::display_confirmation_message(get_lang('ChangesStored'));
  189. }
  190. echo $_SESSION['oLP']->overview();
  191. /* FOOTER */
  192. Display::display_footer();