lp_upload.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. $current_dir = replace_dangerous_char(trim($_POST['current_dir']),'strict');
  16. $uncompress = 1;
  17. //error_log('New LP - lp_upload.php',0);
  18. /*
  19. * check the request method in place of a variable from POST
  20. * because if the file size exceed the maximum file upload
  21. * size set in php.ini, all variables from POST are cleared !
  22. */
  23. if ($_SERVER['REQUEST_METHOD'] == 'POST'
  24. && count($_FILES)>0
  25. && !empty($_FILES['user_file']['name'])
  26. )
  27. {
  28. // A file upload has been detected, now deal with the file...
  29. //directory creation
  30. $stopping_error = false;
  31. $s=$_FILES['user_file']['name'];
  32. //get name of the zip file without the extension
  33. $info = pathinfo($s);
  34. $filename = $info['basename'];
  35. $extension = $info['extension'];
  36. $file_base_name = str_replace('.'.$extension,'',$filename);
  37. $new_dir = replace_dangerous_char(trim($file_base_name),'strict');
  38. require_once('learnpath.class.php');
  39. $type = learnpath::get_package_type($_FILES['user_file']['tmp_name'],$_FILES['user_file']['name']);
  40. switch($type){
  41. case 'scorm':
  42. require_once('scorm.class.php');
  43. $oScorm = new scorm();
  44. $manifest = $oScorm->import_package($_FILES['user_file'],$current_dir);
  45. if(!empty($manifest)){
  46. $oScorm->parse_manifest($manifest);
  47. $oScorm->import_manifest(api_get_course_id());
  48. }else{
  49. //show error message stored in $oScrom->error_msg
  50. }
  51. $proximity = '';
  52. if(!empty($_REQUEST['content_proximity'])){$proximity = mysql_real_escape_string($_REQUEST['content_proximity']);}
  53. $maker = '';
  54. if(!empty($_REQUEST['content_maker'])){$maker = mysql_real_escape_string($_REQUEST['content_maker']);}
  55. $oScorm->set_proximity($proximity);
  56. $oScorm->set_maker($maker);
  57. $oScorm->set_jslib('scorm_api.php');
  58. break;
  59. case 'aicc':
  60. require_once('aicc.class.php');
  61. $oAICC = new aicc();
  62. $config_dir = $oAICC->import_package($_FILES['user_file']);
  63. if(!empty($config_dir)){
  64. $oAICC->parse_config_files($config_dir);
  65. $oAICC->import_aicc(api_get_course_id());
  66. }
  67. $proximity = '';
  68. if(!empty($_REQUEST['content_proximity'])){$proximity = mysql_real_escape_string($_REQUEST['content_proximity']);}
  69. $maker = '';
  70. if(!empty($_REQUEST['content_maker'])){$maker = mysql_real_escape_string($_REQUEST['content_maker']);}
  71. $oAICC->set_proximity($proximity);
  72. $oAICC->set_maker($maker);
  73. $oAICC->set_jslib('aicc_api.php');
  74. break;
  75. case 'oogie':
  76. require_once('openoffice_presentation.class.php');
  77. $take_slide_name = empty($_POST['take_slide_name']) ? false : true;
  78. $o_ppt = new OpenofficePresentation($take_slide_name);
  79. $first_item_id = $o_ppt -> convert_document($_FILES['user_file']);
  80. break;
  81. case 'woogie':
  82. require_once('openoffice_text_document.class.php');
  83. $split_steps = $_POST['split_steps'];
  84. $o_doc = new OpenofficeTextDocument($split_steps);
  85. $first_item_id = $o_doc -> convert_document($_FILES['user_file']);
  86. break;
  87. case '':
  88. default:
  89. return api_failure::set_failure('not_a_learning_path');
  90. }
  91. } // end if is_uploaded_file
  92. elseif($_SERVER['REQUEST_METHOD'] == 'POST')
  93. {
  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_CODE_PATH).'garbage/'.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(!empty($manifest)){
  114. $oScorm->parse_manifest($manifest);
  115. $oScorm->import_manifest(api_get_course_id());
  116. }
  117. $proximity = '';
  118. if(!empty($_REQUEST['content_proximity'])){$proximity = mysql_real_escape_string($_REQUEST['content_proximity']);}
  119. $maker = '';
  120. if(!empty($_REQUEST['content_maker'])){$maker = mysql_real_escape_string($_REQUEST['content_maker']);}
  121. $oScorm->set_proximity($proximity);
  122. $oScorm->set_maker($maker);
  123. $oScorm->set_jslib('scorm_api.php');
  124. break;
  125. case 'aicc':
  126. require_once('aicc.class.php');
  127. $oAICC = new aicc();
  128. $config_dir = $oAICC->import_local_package($s,$current_dir);
  129. if(!empty($config_dir)){
  130. $oAICC->parse_config_files($config_dir);
  131. $oAICC->import_aicc(api_get_course_id());
  132. }
  133. $proximity = '';
  134. if(!empty($_REQUEST['content_proximity'])){$proximity = mysql_real_escape_string($_REQUEST['content_proximity']);}
  135. $maker = '';
  136. if(!empty($_REQUEST['content_maker'])){$maker = mysql_real_escape_string($_REQUEST['content_maker']);}
  137. $oAICC->set_proximity($proximity);
  138. $oAICC->set_maker($maker);
  139. $oAICC->set_jslib('aicc_api.php');
  140. break;
  141. case '':
  142. default:
  143. return api_failure::set_failure('not_a_learning_path');
  144. }
  145. }
  146. ?>