lp_upload.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Script managing the learnpath upload. To best treat the uploaded file, make sure we can identify it.
  5. * @package chamilo.learnpath
  6. * @author Yannick Warnier <ywarnier@beeznest.org>
  7. */
  8. /**
  9. * Code
  10. */
  11. // Flag to allow for anonymous user - needs to be set before global.inc.php.
  12. $use_anonymous = true;
  13. require_once 'back_compat.inc.php';
  14. $course_dir = api_get_course_path().'/scorm';
  15. $course_sys_dir = api_get_path(SYS_COURSE_PATH).$course_dir;
  16. if (empty($_POST['current_dir'])) {
  17. $current_dir = '';
  18. } else {
  19. $current_dir = replace_dangerous_char(trim($_POST['current_dir']), 'strict');
  20. }
  21. $uncompress = 1;
  22. //error_log('New LP - lp_upload.php', 0);
  23. /*
  24. * Check the request method in place of a variable from POST
  25. * because if the file size exceed the maximum file upload
  26. * size set in php.ini, all variables from POST are cleared !
  27. */
  28. if ($_SERVER['REQUEST_METHOD'] == 'POST' && count($_FILES) > 0 && !empty($_FILES['user_file']['name'])) {
  29. // A file upload has been detected, now deal with the file...
  30. // Directory creation.
  31. $stopping_error = false;
  32. $s = $_FILES['user_file']['name'];
  33. // Get name of the zip file without the extension.
  34. $info = pathinfo($s);
  35. $filename = $info['basename'];
  36. $extension = $info['extension'];
  37. $file_base_name = str_replace('.'.$extension, '', $filename);
  38. $new_dir = replace_dangerous_char(trim($file_base_name), 'strict');
  39. require_once 'learnpath.class.php';
  40. $type = learnpath::get_package_type($_FILES['user_file']['tmp_name'], $_FILES['user_file']['name']);
  41. $proximity = 'local';
  42. if (!empty($_REQUEST['content_proximity'])) {
  43. $proximity = Database::escape_string($_REQUEST['content_proximity']);
  44. }
  45. $maker = 'Scorm';
  46. if (!empty($_REQUEST['content_maker'])) {
  47. $maker = Database::escape_string($_REQUEST['content_maker']);
  48. }
  49. switch ($type) {
  50. case 'scorm':
  51. require_once 'scorm.class.php';
  52. $oScorm = new scorm();
  53. $manifest = $oScorm->import_package($_FILES['user_file'], $current_dir);
  54. if (!$manifest) { //if api_set_failure
  55. return api_failure::set_failure(api_failure::get_last_failure());
  56. }
  57. if (!empty($manifest)) {
  58. $oScorm->parse_manifest($manifest);
  59. $oScorm->import_manifest(api_get_course_id(),$_REQUEST['use_max_score']);
  60. } else {
  61. // Show error message stored in $oScrom->error_msg.
  62. }
  63. $oScorm->set_proximity($proximity);
  64. $oScorm->set_maker($maker);
  65. $oScorm->set_jslib('scorm_api.php');
  66. break;
  67. case 'aicc':
  68. require_once 'aicc.class.php';
  69. $oAICC = new aicc();
  70. $config_dir = $oAICC->import_package($_FILES['user_file']);
  71. if (!empty($config_dir)) {
  72. $oAICC->parse_config_files($config_dir);
  73. $oAICC->import_aicc(api_get_course_id());
  74. }
  75. $oAICC->set_proximity($proximity);
  76. $oAICC->set_maker($maker);
  77. $oAICC->set_jslib('aicc_api.php');
  78. break;
  79. case 'oogie':
  80. require_once 'openoffice_presentation.class.php';
  81. $take_slide_name = empty($_POST['take_slide_name']) ? false : true;
  82. $o_ppt = new OpenofficePresentation($take_slide_name);
  83. $first_item_id = $o_ppt -> convert_document($_FILES['user_file']);
  84. break;
  85. case 'woogie':
  86. require_once 'openoffice_text.class.php';
  87. $split_steps = $_POST['split_steps'];
  88. $o_doc = new OpenofficeText($split_steps);
  89. $first_item_id = $o_doc -> convert_document($_FILES['user_file']);
  90. break;
  91. case '':
  92. default:
  93. return api_failure::set_failure('not_a_learning_path');
  94. }
  95. } elseif($_SERVER['REQUEST_METHOD'] == 'POST') {
  96. // end if is_uploaded_file
  97. // If file name given to get in claroline/upload/, try importing this way.
  98. // A file upload has been detected, now deal with the file...
  99. // Directory creation.
  100. $stopping_error = false;
  101. // Escape path with basename so it can only be directly into the claroline/upload directory.
  102. $s = api_get_path(SYS_ARCHIVE_PATH).basename($_POST['file_name']);
  103. // Get name of the zip file without the extension
  104. $info = pathinfo($s);
  105. $filename = $info['basename'];
  106. $extension = $info['extension'];
  107. $file_base_name = str_replace('.'.$extension, '', $filename);
  108. $new_dir = replace_dangerous_char(trim($file_base_name), 'strict');
  109. require_once 'learnpath.class.php';
  110. $type = learnpath::get_package_type($s, basename($s));
  111. switch ($type) {
  112. case 'scorm':
  113. require_once 'scorm.class.php';
  114. $oScorm = new scorm();
  115. $manifest = $oScorm->import_local_package($s, $current_dir);
  116. if ($manifest === false ) { //if api_set_failure
  117. return api_failure::set_failure(api_failure::get_last_failure());
  118. }
  119. if (!empty($manifest)) {
  120. $oScorm->parse_manifest($manifest);
  121. $oScorm->import_manifest(api_get_course_id(), $_REQUEST['use_max_score']);
  122. }
  123. $proximity = '';
  124. if (!empty($_REQUEST['content_proximity'])) { $proximity = Database::escape_string($_REQUEST['content_proximity']); }
  125. $maker = '';
  126. if (!empty($_REQUEST['content_maker'])) {$maker = Database::escape_string($_REQUEST['content_maker']); }
  127. $oScorm->set_proximity($proximity);
  128. $oScorm->set_maker($maker);
  129. $oScorm->set_jslib('scorm_api.php');
  130. break;
  131. case 'aicc':
  132. require_once 'aicc.class.php';
  133. $oAICC = new aicc();
  134. $config_dir = $oAICC->import_local_package($s, $current_dir);
  135. if (!empty($config_dir)) {
  136. $oAICC->parse_config_files($config_dir);
  137. $oAICC->import_aicc(api_get_course_id());
  138. }
  139. $proximity = '';
  140. if (!empty($_REQUEST['content_proximity'])) { $proximity = Database::escape_string($_REQUEST['content_proximity']); }
  141. $maker = '';
  142. if (!empty($_REQUEST['content_maker'])) { $maker = Database::escape_string($_REQUEST['content_maker']); }
  143. $oAICC->set_proximity($proximity);
  144. $oAICC->set_maker($maker);
  145. $oAICC->set_jslib('aicc_api.php');
  146. break;
  147. case '':
  148. default:
  149. return api_failure::set_failure('not_a_learning_path');
  150. }
  151. }