lp_upload.php 5.5 KB

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