lp_upload.php 6.7 KB

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