openoffice_document.class.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php //$id:$
  2. /**
  3. * Defines the AICC class, which is meant to contain the aicc items (nuclear elements)
  4. * @package dokeos.learnpath.aicc
  5. * @author Yannick Warnier <ywarnier@beeznest.org>
  6. * @license GNU/GPL - See Dokeos license directory for details
  7. */
  8. /**
  9. * Defines the "aicc" child of class "learnpath"
  10. * @package dokeos.learnpath.aicc
  11. */
  12. abstract class OpenofficeDocument extends learnpath {
  13. public $first_item = 0;
  14. /**
  15. * Class constructor. Based on the parent constructor.
  16. * @param string Course code
  17. * @param integer Learnpath ID in DB
  18. * @param integer User ID
  19. */
  20. function OpenofficeDocument($course_code=null,$resource_id=null,$user_id=null) {
  21. if($this->debug>0){error_log('In OpenofficeDocument::OpenofficeDocument()',0);}
  22. if(!empty($course_code) and !empty($resource_id) and !empty($user_id))
  23. {
  24. parent::learnpath($course_code, $resource_id, $user_id);
  25. }else{
  26. //do nothing but still build the presentation object
  27. }
  28. }
  29. function convert_document($file, $action_after_conversion='make_lp'){
  30. global $_course, $_user, $_configuration;
  31. $this->file_name = (strrpos($file['name'],'.')>0 ? substr($file['name'], 0, strrpos($file['name'],'.')) : $file['name']);
  32. $this->file_name = remove_accents($this->file_name);
  33. $this->file_name = replace_dangerous_char($this->file_name,'strict');
  34. $this->file_name = strtolower($this->file_name);
  35. $this->file_path = $this->file_name.'.'.pathinfo($file['name'],PATHINFO_EXTENSION);
  36. $dir_name = '/'.$this->file_name;
  37. //create the directory
  38. $this->base_work_dir = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
  39. $visio_dir = ($action_after_conversion=='add_docs_to_visio')?VIDEOCONF_UPLOAD_PATH:'';
  40. $this->created_dir = create_unexisting_directory($_course,$_user['user_id'],0,0,$this->base_work_dir,$visio_dir.$dir_name);
  41. move_uploaded_file($file['tmp_name'],$this->base_work_dir.'/'.$this->file_path);
  42. $perm = api_get_setting('permissions_for_new_files');
  43. $classpath = '-cp .:jodconverter-2.2.1.jar:jodconverter-cli-2.2.1.jar';
  44. if(strpos($_ENV['OS'],'Windows') !== false)
  45. {
  46. $classpath = str_replace(':',';',$classpath);
  47. }
  48. if(strpos($_ENV['OS'],'Windows') !== false)
  49. {
  50. $cmd = 'cd '.str_replace('/','\\',api_get_path(SYS_PATH).'main/inc/lib/ppt2png ').$classpath.' DokeosConverter';
  51. }
  52. else
  53. {
  54. $cmd = 'cd '.api_get_path(SYS_PATH).'main/inc/lib/ppt2png && java '.$classpath.' DokeosConverter';
  55. }
  56. $cmd .= ' -p '.api_get_setting('service_ppt2lp','port');
  57. // call to the function implemented by child
  58. $cmd .= $this -> add_command_parameters();
  59. $cmd .= ' "'.$this->base_work_dir.'/'.$this->file_path.'" "'.$this->base_work_dir.$this->created_dir.'.html"';
  60. // to allow openoffice to manipulate docs.
  61. chmod ($this->base_work_dir.$this->created_dir,0777);
  62. chmod($this->base_work_dir.'/'.$this->file_path,0777);
  63. $shell = exec($cmd, $files, $return);
  64. if($return != 0) { //if the java application returns an error code
  65. DocumentManager::delete_document($_course, $dir_name, $this->base_work_dir);
  66. return false;
  67. }
  68. // create lp
  69. $this->lp_id = learnpath::add_lp($_course['id'], $this->file_name,'','guess','manual');
  70. // call to the function implemented by child following action_after_conversion parameter
  71. switch ($action_after_conversion)
  72. {
  73. case 'make_lp':$this -> make_lp($files);
  74. break;
  75. case 'add_docs_to_visio':$this -> add_docs_to_visio($files);
  76. break;
  77. }
  78. $perm = api_get_setting('permissions_for_new_directories');
  79. $perm = octdec(!empty($perm)?$perm:0770);
  80. chmod ($this->base_work_dir.$this->created_dir,$perm);
  81. return $this->first_item;
  82. }
  83. abstract function make_lp();
  84. abstract function add_docs_to_visio();
  85. abstract function add_command_parameters();
  86. }
  87. ?>