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

Source for file openoffice_document.class.php

Documentation is available at openoffice_document.class.php

  1. <?php //$id:$
  2. /**
  3.  * Defines the OpenOfficeDocument class, which is meant as a mother class
  4.  * to help in the conversion of Office documents to learning paths
  5.  * @package dokeos.learnpath.openofficedocument
  6.  * @author    Eric Marguin <eric.marguin@dokeos.com>
  7.  * @license    GNU/GPL - See Dokeos license directory for details
  8.  */
  9. /**
  10.  * Defines the "OpenofficeDocument" child of class "learnpath"
  11.  * @package dokeos.learnpath.aicc
  12.  */
  13.  
  14. abstract class OpenofficeDocument extends learnpath {
  15.     
  16.  
  17.     public $first_item = 0;
  18.     public $original_charset = 'utf-8';
  19.     public $original_locale = 'en_US.UTF-8';
  20.  
  21.     /**
  22.      * Class constructor. Based on the parent constructor.
  23.      * @param    string    Course code
  24.      * @param    integer    Learnpath ID in DB
  25.      * @param    integer    User ID
  26.      */
  27.     function OpenofficeDocument($course_code=null,$resource_id=null,$user_id=null{
  28.         if($this->debug>0){error_log('In OpenofficeDocument::OpenofficeDocument()',0);}
  29.         if(!empty($course_codeand !empty($resource_idand !empty($user_id))
  30.         {
  31.             parent::learnpath($course_code$resource_id$user_id);
  32.         }else{
  33.             //do nothing but still build the presentation object
  34.         }
  35.     }
  36.     
  37.     function convert_document($file$action_after_conversion='make_lp'){
  38.         
  39.         global $_course$_user$_configuration;
  40.     
  41.         $this->file_name (strrpos($file['name'],'.')>substr($file['name']0strrpos($file['name'],'.')) $file['name']);
  42.         $this->file_name remove_accents($this->file_name);
  43.         $this->file_name replace_dangerous_char($this->file_name,'strict');    
  44.         $this->file_name strtolower($this->file_name);
  45.  
  46.         $visio_dir ($action_after_conversion=='add_docs_to_visio')?VIDEOCONF_UPLOAD_PATH:'';
  47.         
  48.         $this->file_path $visio_dir.'/'.$this->file_name.'.'.pathinfo($file['name'],PATHINFO_EXTENSION);
  49.  
  50.         $dir_name $visio_dir.'/'.$this->file_name;
  51.         
  52.     
  53.         //create the directory        
  54.         $this->base_work_dir api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
  55.         
  56.         
  57.         $this->created_dir create_unexisting_directory($_course,$_user['user_id'],0,0,$this->base_work_dir,$dir_name);
  58.  
  59.         move_uploaded_file($file['tmp_name'],$this->base_work_dir.'/'.$this->file_path);
  60.  
  61.  
  62.         $perm api_get_setting('permissions_for_new_files');
  63.         
  64.         
  65.         $classpath '-cp .:jodconverter-2.2.1.jar:jodconverter-cli-2.2.1.jar';
  66.         if(strpos($_ENV['OS'],'Windows'!== false)
  67.         {
  68.             $classpath str_replace(':',';',$classpath);
  69.         }
  70.         if(strpos($_ENV['OS'],'Windows'!== false)
  71.         {
  72.             $cmd 'cd '.str_replace('/','\\',api_get_path(SYS_PATH).'main/inc/lib/ppt2png ').$classpath.' DokeosConverter';
  73.         }
  74.         else
  75.         {
  76.             $cmd 'cd '.api_get_path(SYS_PATH).'main/inc/lib/ppt2png && java '.$classpath.' DokeosConverter';
  77.         }
  78.         $cmd .=  ' -p '.api_get_setting('service_ppt2lp','port');        
  79.         
  80.         // call to the function implemented by child
  81.         $cmd .= $this -> add_command_parameters();    
  82.  
  83.         // to allow openoffice to manipulate docs.
  84.         chmod ($this->base_work_dir.$this->created_dir,0777);
  85.         chmod ($this->base_work_dir.'/'.$this->file_path,0777);
  86.         
  87.         $locale $this->original_locale// TODO : improve it because we're not sure this locale is present everywhere
  88.         putenv('LC_ALL='.$locale);
  89.         $shell exec($cmd$files$return);
  90.         if($return != 0//if the java application returns an error code
  91.             switch($return)
  92.             {
  93.                 // can't connect to openoffice
  94.                 case $this->error get_lang('CannotConnectToOpenOffice');break;
  95.                 
  96.                 // conversion failed in openoffice
  97.                 case $this->error get_lang('OogieConversionFailed');break;
  98.                 
  99.                 // conversion can't be launch because command failed
  100.                 case 255 $this->error get_lang('OogieUnknownError');break;
  101.             }
  102.             
  103.             DocumentManager::delete_document($_course$dir_name$this->base_work_dir);    
  104.             return false;   
  105.                 
  106.         }
  107.         
  108.         // create lp
  109.         $this->lp_id learnpath::add_lp($_course['id']ucfirst(pathinfo($file['name']PATHINFO_FILENAME)),'','guess','manual');
  110.         
  111.         // call to the function implemented by child following action_after_conversion parameter
  112.         switch ($action_after_conversion)
  113.         {
  114.             case 'make_lp':$this -> make_lp($files);    
  115.             break;        
  116.             case 'add_docs_to_visio':$this -> add_docs_to_visio($files);    
  117.             break;    
  118.         }
  119.                 
  120.         $perm api_get_setting('permissions_for_new_directories');
  121.         $perm octdec(!empty($perm)?$perm:0770);
  122.         chmod ($this->base_work_dir.$this->created_dir,$perm);
  123.         return $this->first_item;       
  124.         
  125.     }
  126.  
  127.     
  128.     abstract function make_lp();
  129.     abstract function add_docs_to_visio();
  130.     abstract function add_command_parameters();
  131.    
  132.         
  133. }
  134. ?>

Documentation generated on Thu, 12 Jun 2008 14:09:01 -0500 by phpDocumentor 1.4.1