presentation.class.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. class presentation extends learnpath {
  13. /**
  14. * Class constructor. Based on the parent constructor.
  15. * @param string Course code
  16. * @param integer Learnpath ID in DB
  17. * @param integer User ID
  18. */
  19. function presentation($course_code=null,$resource_id=null,$user_id=null) {
  20. if($this->debug>0){error_log('In presentation::presentation()',0);}
  21. if(!empty($course_code) and !empty($resource_id) and !empty($user_id))
  22. {
  23. parent::learnpath($course_code, $resource_id, $user_id);
  24. }else{
  25. //do nothing but still build the presentation object
  26. }
  27. }
  28. function convert_presentation($file){
  29. global $_course, $_user, $_configuration;
  30. $file_name = (strrpos($file['name'],'.')>0 ? substr($file['name'], 0, strrpos($file['name'],'.')) : $file['name']);
  31. $file_extension = (strrpos($file['name'],'.')>0 ? substr($file['name'], strrpos($file['name'],'.'),10) : '');
  32. $file_name = remove_accents($file_name);
  33. $file_name = replace_dangerous_char($file_name,'strict');
  34. $file_name = strtolower($file_name);
  35. $file['name'] = $file_name.$file_extension;
  36. $dir_name = '/'.$file_name.'_dir';
  37. // get properties of ppt file
  38. $document_datas = DocumentManager::get_all_document_data($_course, $file);
  39. $to_group_id = (empty($document_datas['to_group_id'])) ? 0 : $document_datas['to_group_id'];
  40. $to_user_id = (empty($document_datas['to_user_id'])) ? null : $document_datas['to_user_id'];
  41. //create the directory
  42. $base_work_dir = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
  43. $created_dir = create_unexisting_directory($_course,$_user['user_id'],$to_group_id,$to_user_id,$base_work_dir,$dir_name);
  44. move_uploaded_file($file['tmp_name'],$base_work_dir.$file['name']);
  45. $file = $base_work_dir.$file['name'];
  46. chmod($file,0777);
  47. /*
  48. * exec java application
  49. * the parameters of the program are :
  50. * - javacommand on this server ;
  51. * - host where openoffice is running;
  52. * - port with which openoffice is listening
  53. * - file to convert
  54. * - folder where put the slides
  55. * - ftppassword if required
  56. * The program fills $files with the list of slides created
  57. */
  58. $classpath = '-cp .:ridl.jar:js.jar:juh.jar:jurt.jar:jut.jar:java_uno.jar:java_uno_accessbridge.jar:edtftpj-1.5.2.jar:unoil.jar';
  59. if(strpos($_ENV['OS'],'Windows') !== false)
  60. {
  61. $classpath = str_replace(':',';',$classpath);
  62. }
  63. list($slide_width, $slide_height) = explode('x',api_get_setting('service_ppt2lp','size'));
  64. if(strpos($_ENV['OS'],'Windows') !== false)
  65. {
  66. $cmd = 'cd '.str_replace('/','\\',api_get_path(SYS_PATH)).'main/inc/lib/ppt2png && java '.$classpath.' DocumentConverter '.api_get_setting('service_ppt2lp','host').' 2002'.' "'.$file.'" "'.$base_work_dir.$created_dir.'"'.' '.$slide_width.' '.$slide_height.' '.api_get_setting('service_ppt2lp','user').' '.api_get_setting('service_ppt2lp','ftp_password');
  67. }
  68. else
  69. {
  70. $cmd = 'cd '.api_get_path(SYS_PATH).'main/inc/lib/ppt2png && java '.$classpath.' DocumentConverter '.api_get_setting('service_ppt2lp','host').' 2002'.' "'.$file.'" "'.$base_work_dir.$created_dir.'"'.' '.$slide_width.' '.$slide_height.' '.api_get_setting('service_ppt2lp','user').' '.api_get_setting('service_ppt2lp','ftp_password');
  71. }
  72. chmod ($base_work_dir.$created_dir,0777);
  73. $shell = exec($cmd, $files, $return);
  74. chmod ($base_work_dir.$created_dir,0744);
  75. if($return != 0) { //if the java application returns an error code
  76. DocumentManager::delete_document($_course, $dir_name, $base_work_dir);
  77. return false;
  78. }
  79. else {
  80. // create lp
  81. $learnpath_name .= $file_name;
  82. $this->lp_id = learnpath::add_lp($_course['id'], $learnpath_name,'','guess','manual');
  83. $previous = 0;
  84. $i = 0;
  85. $first_item = 0;
  86. foreach($files as $file){
  87. $i++;
  88. // create an html file
  89. $html_file = $file.'.html';
  90. $fp = fopen($base_work_dir.$created_dir.'/'.$html_file, 'w+');
  91. fwrite($fp,
  92. '<html>
  93. <head></head>
  94. <body>
  95. <img src="'.$_configuration['url_append'].'/courses/'.$_course['path'].'/document'.$created_dir.'/'.$file.'" />
  96. </body>
  97. </html>');
  98. fclose($fp);
  99. $document_id = add_document($_course,$created_dir.'/'.$html_file,'file',filesize($base_work_dir.$created_dir.'/'.$html_file),$html_file);
  100. if ($document_id){
  101. //put the document in item_property update
  102. api_item_property_update($_course,TOOL_DOCUMENT,$document_id,'DocumentAdded',$_SESSION['_uid'],$to_group_id,$to_user_id);
  103. $infos = pathinfo($file);
  104. $slide_name = 'slide'.str_repeat('0',2-strlen($i)).$i;
  105. $previous = learnpath::add_item(0, $previous, 'document', $document_id, $slide_name, '');
  106. if($first_item == 0){
  107. $first_item = $previous;
  108. }
  109. }
  110. }
  111. }
  112. return $first_item;
  113. }
  114. }
  115. ?>