openoffice_document.class.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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
  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. abstract class OpenofficeDocument extends learnpath {
  14. public $first_item = 0;
  15. public $original_charset = 'utf-8';
  16. public $original_locale = 'en_US.UTF-8';
  17. /**
  18. * Class constructor. Based on the parent constructor.
  19. * @param string Course code
  20. * @param integer Learnpath ID in DB
  21. * @param integer User ID
  22. */
  23. function OpenofficeDocument($course_code=null,$resource_id=null,$user_id=null) {
  24. if($this->debug>0){error_log('In OpenofficeDocument::OpenofficeDocument()',0);}
  25. if(!empty($course_code) and !empty($resource_id) and !empty($user_id))
  26. {
  27. parent::learnpath($course_code, $resource_id, $user_id);
  28. }else{
  29. //do nothing but still build the presentation object
  30. }
  31. }
  32. function convert_document($file, $action_after_conversion='make_lp'){
  33. global $_course, $_user, $_configuration;
  34. $this->file_name = (strrpos($file['name'],'.')>0 ? substr($file['name'], 0, strrpos($file['name'],'.')) : $file['name']);
  35. $this->file_name = remove_accents($this->file_name);
  36. $this->file_name = replace_dangerous_char($this->file_name,'strict');
  37. $this->file_name = strtolower($this->file_name);
  38. $visio_dir = ($action_after_conversion=='add_docs_to_visio')?VIDEOCONF_UPLOAD_PATH:'';
  39. $this->file_path = $visio_dir.'/'.$this->file_name.'.'.pathinfo($file['name'],PATHINFO_EXTENSION);
  40. $dir_name = $visio_dir.'/'.$this->file_name;
  41. //create the directory
  42. $this->base_work_dir = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
  43. $this->created_dir = create_unexisting_directory($_course,$_user['user_id'],0,0,$this->base_work_dir,$dir_name);
  44. move_uploaded_file($file['tmp_name'],$this->base_work_dir.'/'.$this->file_path);
  45. $perm = api_get_setting('permissions_for_new_files');
  46. $classpath = '-cp .:jodconverter-2.2.1.jar:jodconverter-cli-2.2.1.jar';
  47. if(strpos($_ENV['OS'],'Windows') !== false)
  48. {
  49. $classpath = str_replace(':',';',$classpath);
  50. }
  51. if(strpos($_ENV['OS'],'Windows') !== false)
  52. {
  53. $cmd = 'cd '.str_replace('/','\\',api_get_path(SYS_PATH).'main/inc/lib/ppt2png ').$classpath.' DokeosConverter';
  54. }
  55. else
  56. {
  57. $cmd = 'cd '.api_get_path(SYS_PATH).'main/inc/lib/ppt2png && java '.$classpath.' DokeosConverter';
  58. }
  59. $cmd .= ' -p '.api_get_setting('service_ppt2lp','port');
  60. // call to the function implemented by child
  61. $cmd .= $this -> add_command_parameters();
  62. // to allow openoffice to manipulate docs.
  63. chmod ($this->base_work_dir.$this->created_dir,0777);
  64. chmod ($this->base_work_dir.'/'.$this->file_path,0777);
  65. $locale = $this->original_locale; // TODO : improve it because we're not sure this locale is present everywhere
  66. putenv('LC_ALL='.$locale);
  67. $shell = exec($cmd, $files, $return);
  68. if($return != 0) { //if the java application returns an error code
  69. switch($return)
  70. {
  71. // can't connect to openoffice
  72. case 1 : $this->error = get_lang('CannotConnectToOpenOffice');break;
  73. // conversion failed in openoffice
  74. case 2 : $this->error = get_lang('OogieConversionFailed');break;
  75. // conversion can't be launch because command failed
  76. case 255 : $this->error = get_lang('OogieUnknownError');break;
  77. }
  78. DocumentManager::delete_document($_course, $dir_name, $this->base_work_dir);
  79. return false;
  80. }
  81. // create lp
  82. $this->lp_id = learnpath::add_lp($_course['id'], ucfirst(pathinfo($file['name'], PATHINFO_FILENAME)),'','guess','manual');
  83. // call to the function implemented by child following action_after_conversion parameter
  84. switch ($action_after_conversion)
  85. {
  86. case 'make_lp':$this -> make_lp($files);
  87. break;
  88. case 'add_docs_to_visio':$this -> add_docs_to_visio($files);
  89. break;
  90. }
  91. $perm = api_get_setting('permissions_for_new_directories');
  92. $perm = octdec(!empty($perm)?$perm:0770);
  93. chmod ($this->base_work_dir.$this->created_dir,$perm);
  94. return $this->first_item;
  95. }
  96. abstract function make_lp();
  97. abstract function add_docs_to_visio();
  98. abstract function add_command_parameters();
  99. }
  100. ?>