Browse Source

Minor - cleaning scorm upload form

Julio Montoya 13 years ago
parent
commit
627c4aee20
4 changed files with 31 additions and 26 deletions
  1. 6 2
      main/newscorm/lp_upload.php
  2. 8 7
      main/upload/form.scorm.php
  3. 1 2
      main/upload/upload.php
  4. 16 15
      main/upload/upload.scorm.php

+ 6 - 2
main/newscorm/lp_upload.php

@@ -36,6 +36,7 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST' && count($_FILES) > 0 && !empty($_FILES
     $stopping_error = false;
 
     $s = $_FILES['user_file']['name'];
+     
     // Get name of the zip file without the extension.
     $info = pathinfo($s);
     $filename = $info['basename'];
@@ -43,9 +44,11 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST' && count($_FILES) > 0 && !empty($_FILES
     $file_base_name = str_replace('.'.$extension, '', $filename);
 
     $new_dir = replace_dangerous_char(trim($file_base_name), 'strict');
+    
 
     require_once 'learnpath.class.php';
     $type = learnpath::get_package_type($_FILES['user_file']['tmp_name'], $_FILES['user_file']['name']);
+   
     
     $proximity = 'local';
     if (!empty($_REQUEST['content_proximity'])) {
@@ -102,8 +105,9 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST' && count($_FILES) > 0 && !empty($_FILES
         default:
             return api_failure::set_failure('not_a_learning_path');
     }
-} // end if is_uploaded_file
-elseif($_SERVER['REQUEST_METHOD'] == 'POST') {
+} elseif($_SERVER['REQUEST_METHOD'] == 'POST') {
+    // end if is_uploaded_file
+    
     // If file name given to get in claroline/upload/, try importing this way.
 
     // A file upload has been detected, now deal with the file...

+ 8 - 7
main/upload/form.scorm.php

@@ -33,13 +33,12 @@ function get_zip_files_in_garbage(){
  * Just display the form needed to upload a SCORM and give its settings
  */
 $nameTools = get_lang("FileUpload");
-$interbreadcrumb[]= array ("url"=>"../newscorm/lp_controller.php?action=list", "name"=> get_lang("Learnpath"));
+$interbreadcrumb[]= array ("url"=>"../newscorm/lp_controller.php?action=list", "name"=> get_lang("ToolLearnpath"));
 Display::display_header($nameTools,"Path");
 //show the title
 //api_display_tool_title(get_lang("Learnpath")." - ".$nameTools.$add_group_to_title);
 //TODO: Include right language file
 
-require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
 require_once '../newscorm/content_makers.inc.php';
 require_once api_get_path(LIBRARY_PATH) . 'specific_fields_manager.lib.php';
 
@@ -53,6 +52,8 @@ $form->addElement('hidden', 'curdirpath', $path);
 $form->addElement('hidden', 'tool', $my_tool);
 
 $form->addElement('file','user_file',get_lang('FileToUpload'));
+$form->add_real_progress_bar('uploadScorm','user_file');
+$form->addRule('user_file', '<div class="required">'.get_lang('ThisFieldIsRequired'), 'required');
 
 /*$select_content_marker = &$form->addElement('select','content_maker',get_lang('ContentMaker'));
 foreach($content_origins as $index => $origin){
@@ -76,7 +77,7 @@ if (api_get_setting('search_enabled')=='true') {
 }
 
 if (api_is_platform_admin()) {
-    $form->addElement('checkbox', 'use_max_score', get_lang('UseMaxScore100'));    
+    $form->addElement('checkbox', 'use_max_score', null, get_lang('UseMaxScore100'));    
 }
 
 $form->addElement('style_submit_button','submit', get_lang('Send'),'class="upload"');
@@ -107,13 +108,13 @@ if(is_dir(api_get_path(PLUGIN_PATH)."/pens")) {
 	}
 }
 
-$form->add_real_progress_bar('uploadScorm','user_file');
-// the rules for the form
-$form->addRule('user_file', '<div class="required">'.get_lang('ThisFieldIsRequired'), 'required');
+
 // the default values for the form
 $defaults = array('index_document'=>'checked="checked"','use_max_score'=>1);
 $form->setDefaults($defaults);
-$form->display();Display::display_normal_message(Display::tag('strong', get_lang('SupportedScormContentMakers')).': '.implode(', ', $content_origins), false);
+Display::display_normal_message(Display::tag('strong', get_lang('SupportedScormContentMakers')).': '.implode(', ', $content_origins), false);
+$form->display();
+
 
 // footer
 Display::display_footer();

+ 1 - 2
main/upload/upload.php

@@ -23,11 +23,10 @@ if(empty($_SESSION['my_tool'])){header('location:index.php');}
 // check access permissions (edit permission is needed to add a document or a LP)
 $is_allowed_to_edit = api_is_allowed_to_edit();
 
-if(!$is_allowed_to_edit){
+if (!$is_allowed_to_edit){
 	api_not_allowed(true);
 }
 
-
 /**
  * Redirect to the correct script to handle this type of upload
  */

+ 16 - 15
main/upload/upload.scorm.php

@@ -15,7 +15,9 @@ $cwdir = getcwd();
 require_once '../newscorm/lp_upload.php';
 //reinit current working directory as many functions in upload change it
 chdir($cwdir);
+
 $error = api_failure::get_last_failure();
+
 if ($error=='not_a_learning_path') {
         $msg = urlencode(get_lang('ScormUnknownPackageFormat'));
 	$dialogtype = 'error';
@@ -27,24 +29,23 @@ if ($error=='not_a_learning_path') {
 	$dialogtype = 'error';
 } else {
 	if (api_get_setting('search_enabled')=='true') {
-          require_once api_get_path(LIBRARY_PATH) . 'specific_fields_manager.lib.php';
-    	  $specific_fields = get_specific_field_list();
+      require_once api_get_path(LIBRARY_PATH) . 'specific_fields_manager.lib.php';
+	  $specific_fields = get_specific_field_list();
 
-    	  foreach ($specific_fields as $specific_field) {
-    		$values = explode(',', trim($_POST[$specific_field['code']]));
-    		if ( !empty($values) ) {
-    			foreach ($values as $value) {
-    				$value = trim($value);
-    				if ( !empty($value) ) {
-    					add_specific_field_value($specific_field['id'], api_get_course_id(), TOOL_LEARNPATH, $oScorm->lp_id, $value);
-    				}
-    			}
-    		}
-    	}
+	  foreach ($specific_fields as $specific_field) {
+		$values = explode(',', trim($_POST[$specific_field['code']]));
+        if ( !empty($values) ) {
+        	foreach ($values as $value) {
+        		$value = trim($value);
+        		if ( !empty($value) ) {
+        			add_specific_field_value($specific_field['id'], api_get_course_id(), TOOL_LEARNPATH, $oScorm->lp_id, $value);
+        			}
+        		}
+        	}
+        }
     }
 	$msg = urlencode(get_lang('UplUploadSucceeded'));
 	$dialogtype = 'confirmation';
 }
 header('location: ../newscorm/lp_controller.php?action=list&dialog_box='.$msg.'&dialogtype='.$dialogtype);
-exit;
-?>
+exit;