dokeos-learnpath
[ class tree: dokeos-learnpath ] [ index: dokeos-learnpath ] [ all elements ]

Source for file lp_upload.php

Documentation is available at lp_upload.php

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

Documentation generated on Thu, 12 Jun 2008 14:03:34 -0500 by phpDocumentor 1.4.1