Browse Source

When using oogie now the files are moved to the "learnpath" folder

Julio Montoya 12 years ago
parent
commit
9ebba86c1e

+ 15 - 9
main/newscorm/learnpath.class.php

@@ -92,7 +92,7 @@ class learnpath {
         // Check course code.
         $course_id = api_get_course_int_id();
 
-        if ($this->debug > 0) {error_log('New LP - In learnpath::__construct('.$course.','.$lp_id.','.$user_id.')', 0); }
+        if ($this->debug > 0) { error_log('New LP - In learnpath::__construct('.$course.','.$lp_id.','.$user_id.')', 0); }
         if (empty($course)) {
             $this->error = 'Course code is empty';
             return false;
@@ -5341,27 +5341,32 @@ class learnpath {
         //Creating learning_path folder
     	$dir = '/learning_path';
     	$filepath = api_get_path(SYS_COURSE_PATH) . $course['path'] . '/document';
-    	$folder = null;
+    	$folder = false;
     	if (!is_dir($filepath.'/'.$dir)) {
-    		$folder = create_unexisting_directory($course, api_get_user_id(), api_get_session_id(), 0, 0, $filepath, $dir , get_lang('LearningPaths'),0);
+    		$folder = create_unexisting_directory($course, api_get_user_id(), api_get_session_id(), 0, 0, $filepath, $dir , get_lang('LearningPaths'), 0);
     	} else {
     		$folder = true;
     	}
         return $folder;
     }
 
-    public function generate_lp_folder($course) {
+    public function generate_lp_folder($course, $lp_name = null) {
     	$filepath = '';
     	$dir = '/learning_path/';
-        $folder = self::generate_learning_path_folder($course);
+        
+        if (empty($lp_name)) {
+            $lp_name = $this->name;
+        }
+        
+        $folder = self::generate_learning_path_folder($course);        
     	//Creating LP folder
     	if ($folder) {
     		//Limits title size
-    		$title = api_substr(replace_dangerous_char($this->name), 0 , 80);
+    		$title = api_substr(replace_dangerous_char($lp_name), 0 , 80);
     		$dir   = $dir.$title;
     		$filepath = api_get_path(SYS_COURSE_PATH) . $course['path'] . '/document';
     		if (!is_dir($filepath.'/'.$dir)) {
-    			$folder = create_unexisting_directory($course, api_get_user_id(), api_get_session_id(), 0, 0, $filepath, $dir , $this->name);
+    			$folder = create_unexisting_directory($course, api_get_user_id(), api_get_session_id(), 0, 0, $filepath, $dir , $lp_name);
     		} else {
     			$folder = true;
     		}
@@ -5370,7 +5375,7 @@ class learnpath {
     			$filepath = api_get_path(SYS_COURSE_PATH) . $course['path'] . '/document'.$dir;
     		}
     	}
-    	$array =  array('dir' => $dir, 'filepath' => $filepath);
+    	$array =  array('dir' => $dir, 'filepath' => $filepath, 'folder' => $folder);
     	return $array;
     }
 
@@ -5395,7 +5400,8 @@ class learnpath {
         $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document' . $dir;
 
         if (empty($_POST['dir']) && empty($_GET['dir'])) {
-        	$result = $this->generate_lp_folder($_course);
+            //Generates folder
+        	$result     = $this->generate_lp_folder($_course);
         	$dir 		= $result['dir'];
         	$filepath 	= $result['filepath'];
         }

+ 1 - 5
main/newscorm/lp_add_item.php

@@ -82,9 +82,6 @@ function check_for_title() {
         }
     }
     temp=true;
-
-        
-        
 }
 
 function InnerDialogLoaded() {
@@ -94,7 +91,6 @@ function InnerDialogLoaded() {
     } else {
         var B=new window.frames[0].FCKToolbarButton(\'Templates\',window.frames[0].FCKLang.Templates);
     }
-
     return 	B.ClickFrame();
 };'."\n".
 
@@ -260,7 +256,7 @@ echo '</div>';
 
 //hide bar div
 if ($action == 'add_item' && $type == 'document' && !isset($_GET['file'])) {    
-    echo '<div id="hide_bar_template" ></div>';    
+    echo '<div id="hide_bar_template"></div>';    
 }
 
 echo '<div id="doc_form" class="span8">';

+ 2 - 4
main/newscorm/lp_upload.php

@@ -62,8 +62,6 @@ if( Request::is_post() && $is_error){
     	$maker = Database::escape_string($_REQUEST['content_maker']);
     }
 
-
-
     switch ($type) {
         case 'scorm':
             require_once 'scorm.class.php';
@@ -98,13 +96,13 @@ if( Request::is_post() && $is_error){
             require_once 'openoffice_presentation.class.php';
             $take_slide_name = empty($_POST['take_slide_name']) ? false : true;
             $o_ppt = new OpenofficePresentation($take_slide_name);
-            $first_item_id = $o_ppt -> convert_document($_FILES['user_file']);
+            $first_item_id = $o_ppt->convert_document($_FILES['user_file']);
             break;
         case 'woogie':
             require_once 'openoffice_text.class.php';
             $split_steps = $_POST['split_steps'];
             $o_doc = new OpenofficeText($split_steps);
-            $first_item_id = $o_doc -> convert_document($_FILES['user_file']);
+            $first_item_id = $o_doc->convert_document($_FILES['user_file']);
             break;
         case '':
         default:

+ 124 - 106
main/newscorm/openoffice_document.class.php

@@ -1,4 +1,5 @@
 <?php
+
 /* For licensing terms, see /license.txt */
 
 /**
@@ -25,7 +26,9 @@ abstract class OpenofficeDocument extends learnpath {
      * @param	integer	User ID
      */
     public function __construct($course_code = null, $resource_id = null, $user_id = null) {
-        if ($this->debug > 0) { error_log('In OpenofficeDocument::OpenofficeDocument()', 0); }
+        if ($this->debug > 0) {
+            error_log('In OpenofficeDocument::OpenofficeDocument()', 0);
+        }
         if (!empty($course_code) && !empty($resource_id) && !empty($user_id)) {
             parent::__construct($course_code, $resource_id, $user_id);
         } else {
@@ -34,7 +37,21 @@ abstract class OpenofficeDocument extends learnpath {
     }
 
     public function convert_document($file, $action_after_conversion = 'make_lp') {
-
+        global $_course, $_user, $_configuration;
+        $this->file_name = pathinfo($file['name'], PATHINFO_FILENAME);        
+        // Create the directory
+        $result = $this->generate_lp_folder($_course, $this->file_name);                        
+                
+         // Create the directory
+        $this->base_work_dir = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
+        ///learning_path/ppt_dirname directory
+        $this->created_dir = substr($result['dir'], 0, strlen($result['dir']) -1);        
+        $this->file_path = $this->created_dir.'/'.replace_dangerous_char($file['name'], 'strict');
+        
+        //var_dump($this->file_name, $this->file_path, $this->base_work_dir, $this->created_dir);
+    
+        /*
+         * Original code
         global $_course, $_user, $_configuration;
 
         $this->file_name = (strrpos($file['name'], '.') > 0 ? substr($file['name'], 0, strrpos($file['name'], '.')) : $file['name']);
@@ -52,84 +69,93 @@ abstract class OpenofficeDocument extends learnpath {
         $this->base_work_dir = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
 
         $this->created_dir = create_unexisting_directory($_course, $_user['user_id'], api_get_session_id(), 0, 0, $this->base_work_dir, $dir_name);
+       
+            var_dump($this->file_name, $this->file_path, $this->base_work_dir, $this->created_dir);
+        
+        */
 
         $ppt2lp_host = api_get_setting('service_ppt2lp', 'host');
 
         if ($ppt2lp_host == 'localhost') {
-          
-          move_uploaded_file($file['tmp_name'], $this->base_work_dir.'/'.$this->file_path);
-          $perm = api_get_setting('permissions_for_new_files');
-          if (IS_WINDOWS_OS) { // IS_WINDOWS_OS has been defined in main_api.lib.php
-              $converter_path = str_replace('/', '\\', api_get_path(SYS_PATH).'main/inc/lib/ppt2png');
-              $class_path = $converter_path.';'.$converter_path.'/jodconverter-2.2.2.jar;'.$converter_path.'/jodconverter-cli-2.2.2.jar';
-              //$cmd = 'java -cp "'.$class_path.'" DokeosConverter';
-              $cmd = 'java -Dfile.encoding=UTF-8 -cp "'.$class_path.'" DokeosConverter';
-          } else {
-              $converter_path = api_get_path(SYS_PATH).'main/inc/lib/ppt2png';
-              //$class_path = '-cp .:jodconverter-2.2.1.jar:jodconverter-cli-2.2.1.jar';
-              $class_path = ' -Dfile.encoding=UTF-8 -cp .:jodconverter-2.2.2.jar:jodconverter-cli-2.2.2.jar';
-              $cmd = 'cd '.$converter_path.' && java '.$class_path.' DokeosConverter';
-          }
-          $cmd .=  ' -p '.api_get_setting('service_ppt2lp', 'port');
-          // Call to the function implemented by child.
-          $cmd .= $this -> add_command_parameters();
-          // To allow openoffice to manipulate docs.
-          @chmod($this->base_work_dir.$this->created_dir, 0777);
-          @chmod($this->base_work_dir.$this->file_path, 0777);
-
-          $locale = $this->original_locale; // TODO: Improve it because we're not sure this locale is present everywhere.
-          putenv('LC_ALL='.$locale);
-
-          $files = array(); $return = 0;
-          $shell = exec($cmd, $files, $return);
-
-          if ($return != 0) { // If the java application returns an error code.
-              switch ($return) {
-                  // Can't connect to openoffice.
-                  case 1: $this->error = get_lang('CannotConnectToOpenOffice'); break;
-                  // Conversion failed in openoffice.
-                  case 2: $this->error = get_lang('OogieConversionFailed'); break;
-                  // Conversion can't be launch because command failed.
-                  case 255: $this->error = get_lang('OogieUnknownError'); break;
-              }
-              DocumentManager::delete_document($_course, $dir_name, $this->base_work_dir);
-              return false;
-          }
+            move_uploaded_file($file['tmp_name'], $this->base_work_dir.'/'.$this->file_path);
+            //var_dump( $this->base_work_dir.$this->created_dir.$this->file_path);
+            $perm = api_get_setting('permissions_for_new_files');
+
+            if (IS_WINDOWS_OS) { // IS_WINDOWS_OS has been defined in main_api.lib.php
+                $converter_path = str_replace('/', '\\', api_get_path(SYS_PATH) . 'main/inc/lib/ppt2png');
+                $class_path = $converter_path . ';' . $converter_path . '/jodconverter-2.2.2.jar;' . $converter_path . '/jodconverter-cli-2.2.2.jar';
+                //$cmd = 'java -cp "'.$class_path.'" DokeosConverter';
+                $cmd = 'java -Dfile.encoding=UTF-8 -cp "' . $class_path . '" DokeosConverter';
+            } else {
+                $converter_path = api_get_path(SYS_PATH) . 'main/inc/lib/ppt2png';
+                //$class_path = '-cp .:jodconverter-2.2.1.jar:jodconverter-cli-2.2.1.jar';
+                $class_path = ' -Dfile.encoding=UTF-8 -cp .:jodconverter-2.2.2.jar:jodconverter-cli-2.2.2.jar';
+                $cmd = 'cd ' . $converter_path . ' && java ' . $class_path . ' DokeosConverter';
+            }
 
+            $cmd .= ' -p ' . api_get_setting('service_ppt2lp', 'port');
+            // Call to the function implemented by child.
+            $cmd .= $this->add_command_parameters();
+            // To allow openoffice to manipulate docs.            
+            @chmod($this->base_work_dir, 0777);
+            @chmod($this->base_work_dir.$this->created_dir, 0777);
+            @chmod($this->base_work_dir.$this->file_path, 0777);
+
+            $locale = $this->original_locale; // TODO: Improve it because we're not sure this locale is present everywhere.
+            putenv('LC_ALL=' . $locale);
+
+            $files = array();
+            $return = 0;
+            $shell = exec($cmd, $files, $return);
+            
+            if ($return != 0) { // If the java application returns an error code.
+                switch ($return) {
+                    // Can't connect to openoffice.
+                    case 1: $this->error = get_lang('CannotConnectToOpenOffice');
+                        break;
+                    // Conversion failed in openoffice.
+                    case 2: $this->error = get_lang('OogieConversionFailed');
+                        break;
+                    // Conversion can't be launch because command failed.
+                    case 255: $this->error = get_lang('OogieUnknownError');
+                        break;
+                }
+                DocumentManager::delete_document($_course, $this->created_dir, $this->base_work_dir);
+                return false;
+            }
         } else {
-
-          // get result from webservices
-          $result = $this->_get_remote_ppt2lp_files($file);
-          $result = unserialize(base64_decode($result));
-
-          // save remote images to server
-          chmod ($this->base_work_dir.$this->created_dir, api_get_permissions_for_new_directories());
-          if (!empty($result['images'])) {
-            foreach ($result['images'] as $image => $img_data) {
-              $image_path = $this->base_work_dir.$this->created_dir;
-              @file_put_contents($image_path.'/'.$image, base64_decode($img_data));
-              @chmod($image_path.'/'.$image, 0777);
+            // get result from webservices
+            $result = $this->_get_remote_ppt2lp_files($file);
+            $result = unserialize(base64_decode($result));
+
+            // Save remote images to server
+            chmod($this->base_work_dir.$this->created_dir, api_get_permissions_for_new_directories());
+            if (!empty($result['images'])) {
+                foreach ($result['images'] as $image => $img_data) {
+                    $image_path = $this->base_work_dir.$this->created_dir;
+                    @file_put_contents($image_path . '/' . $image, base64_decode($img_data));
+                    @chmod($image_path . '/' . $image, 0777);
+                }
             }
-          }
-
-          // files info
-          $files = $result['files'];
 
+            // files info
+            $files = $result['files'];
         }
-
+        
         if (!empty($files)) {
-          // Create lp.
-          $this->lp_id = learnpath::add_lp($_course['id'], ucfirst(pathinfo($file['name'], PATHINFO_FILENAME)), '', 'guess', 'manual');
-
-          // Call to the function implemented by child following action_after_conversion parameter.
-          switch ($action_after_conversion) {
-              case 'make_lp': $this -> make_lp($files);
-                  break;
-              case 'add_docs_to_visio': $this -> add_docs_to_visio($files);
-                  break;
-          }
-
-          chmod ($this->base_work_dir.$this->created_dir, api_get_permissions_for_new_directories());
+            // Create lp
+            $this->lp_id = learnpath::add_lp($_course['id'], $this->file_name, '', 'guess', 'manual');
+
+            // Call to the function implemented by child following action_after_conversion parameter.
+            switch ($action_after_conversion) {
+                case 'make_lp':
+                    $this->make_lp($files);
+                    break;
+                case 'add_docs_to_visio':
+                    $this->add_docs_to_visio($files);
+                    break;
+            }
+            chmod($this->base_work_dir, api_get_permissions_for_new_directories());
         }
         return $this->first_item;
     }
@@ -140,49 +166,41 @@ abstract class OpenofficeDocument extends learnpath {
      * @return  array images files
      */
     private function _get_remote_ppt2lp_files($file) {
+        require_once api_get_path(LIBRARY_PATH) . 'nusoap/nusoap.php';
+        // host
+        $ppt2lp_host = api_get_setting('service_ppt2lp', 'host');
 
-      require_once api_get_path(LIBRARY_PATH).'nusoap/nusoap.php';
-      
-      // host
-      $ppt2lp_host = api_get_setting('service_ppt2lp', 'host');
-
-
-      // secret key
-      $secret_key = sha1(api_get_setting('service_ppt2lp', 'ftp_password'));
-      //$secret_key = sha1($_SERVER['REMOTE_ADDR'].api_get_setting('service_ppt2lp', 'ftp_password'));
-      //error_log('IP:'.$_SERVER['REMOTE_ADDR']);
-      
-      // client
-      $client = new nusoap_client($ppt2lp_host, true);
-
-      $result = '';
-      $err = $client->getError();
-      if (!$err) {
-
-        $file_data  = base64_encode(file_get_contents($file['tmp_name']));
-        $file_name  = $file['name'];
-        $service_ppt2lp_size = api_get_setting('service_ppt2lp', 'size');
-
-        $params = array(
-                      'secret_key'  => $secret_key,
-                      'file_data'   => $file_data,
-                      'file_name'   => $file_name,
-                      'service_ppt2lp_size' => $service_ppt2lp_size,
-                  );
-        
-        $result = $client->call('ws_convert_ppt', array('convert_ppt' => $params));
+        // secret key
+        $secret_key = sha1(api_get_setting('service_ppt2lp', 'ftp_password'));
 
-      } else {
-        return false;
-      }
+        // client
+        $client = new nusoap_client($ppt2lp_host, true);
 
-      return $result;
+        $result = '';
+        $err = $client->getError();
+        if (!$err) {
 
-    }
+            $file_data = base64_encode(file_get_contents($file['tmp_name']));
+            $file_name = $file['name'];
+            $service_ppt2lp_size = api_get_setting('service_ppt2lp', 'size');
+
+            $params = array(
+                'secret_key' => $secret_key,
+                'file_data' => $file_data,
+                'file_name' => $file_name,
+                'service_ppt2lp_size' => $service_ppt2lp_size,
+            );
 
+            $result = $client->call('ws_convert_ppt', array('convert_ppt' => $params));
+        } else {
+            return false;
+        }
+        return $result;
+    }
 
     abstract function make_lp();
+
     abstract function add_docs_to_visio();
-    abstract function add_command_parameters();
 
+    abstract function add_command_parameters();
 }

+ 4 - 16
main/newscorm/openoffice_presentation.class.php

@@ -25,22 +25,19 @@ class OpenofficePresentation extends OpenofficeDocument {
     public $take_slide_name;
 
     public function __construct($take_slide_name = false, $course_code = null, $resource_id = null, $user_id = null) {
-        $this -> take_slide_name = $take_slide_name;
+        $this->take_slide_name = $take_slide_name;
         parent::__construct($course_code, $resource_id, $user_id);
     }
 
 
     public function make_lp($files = array()) {
-
         global $_course;
-
         $previous = 0;
         $i = 0;
 
         if (!is_dir($this->base_work_dir.$this->created_dir))
             return false;
 
-
         foreach ($files as $file) {
 
             list($slide_name, $file_name, $slide_body) = explode('||', $file); // '||' is used as separator between fields: slide name (with accents) || file name (without accents) || all slide text (to be indexed).
@@ -170,11 +167,9 @@ class OpenofficePresentation extends OpenofficeDocument {
     }
 
     function add_command_parameters() {
-
         if (empty($this->slide_width) || empty($this->slide_height))
             list($this->slide_width, $this->slide_height) = explode('x', api_get_setting('service_ppt2lp', 'size'));
         return ' -w '.$this->slide_width.' -h '.$this->slide_height.' -d oogie "'.$this->base_work_dir.'/'.$this->file_path.'"  "'.$this->base_work_dir.$this->created_dir.'.html"';
-
     }
 
     function set_slide_size($width, $height) {
@@ -182,25 +177,18 @@ class OpenofficePresentation extends OpenofficeDocument {
         $this->slide_height = $height;
     }
 
-    function add_docs_to_visio ($files = array()) {
-
+    function add_docs_to_visio($files = array()) {
         global $_course;
-        /* Add Files */
-
         foreach ($files as $file) {
-
             list($slide_name,$file_name) = explode('||',$file); // '||' is used as separator between slide name (with accents) and file name (without accents).
             $slide_name = api_htmlentities($slide_name, ENT_COMPAT, $this->original_charset);
             $slide_name = str_replace('&rsquo;', '\'', $slide_name);
             $slide_name = api_convert_encoding($slide_name, api_get_system_encoding(), $this->original_charset);
             $slide_name = api_html_entity_decode($slide_name, ENT_COMPAT, api_get_system_encoding());
-
             $did = add_document($_course, $this->created_dir.'/'.urlencode($file_name), 'file', filesize($this->base_work_dir.$this->created_dir.'/'.$file_name), $slide_name);
-            if ($did)
+            if ($did) {
                 api_item_property_update($_course, TOOL_DOCUMENT, $did, 'DocumentAdded', $_SESSION['_uid'], 0, null, null, null, api_get_session_id());
-
+            }
         }
-
     }
-
 }