openoffice_presentation.class.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. require_once('openoffice_document.class.php');
  13. class OpenofficePresentation extends OpenofficeDocument {
  14. public $take_slide_name;
  15. function OpenofficePresentation($take_slide_name=false, $course_code=null, $resource_id=null,$user_id=null) {
  16. $this -> take_slide_name = $take_slide_name;
  17. parent::OpenofficeDocument($course_code, $resource_id, $user_id);
  18. }
  19. function make_lp($files=array()) {
  20. global $_course;
  21. $previous = 0;
  22. $i = 0;
  23. if(!is_dir($this->base_work_dir.$this->created_dir))
  24. return false;
  25. foreach($files as $file){
  26. list($slide_name,$file_name) = explode('||',$file); // '||' is used as separator between slide name (with accents) and file name (without accents)
  27. //filename is utf8 encoded, but when we decode, some chars are not translated (like quote &rsquo;).
  28. //so we remove these chars by translating it in htmlentities and the reconvert it in want charset
  29. $slide_name = htmlentities($slide_name,ENT_COMPAT,'utf-8');
  30. $slide_name = str_replace('&rsquo;','\'',$slide_name);
  31. $slide_name = mb_convert_encoding($slide_name, api_get_setting('platform_charset'), 'utf-8');
  32. $slide_name = html_entity_decode($slide_name);
  33. if($this->take_slide_name === true)
  34. {
  35. $slide_name = str_replace('_',' ',$slide_name);
  36. $slide_name = ucfirst($slide_name);
  37. }
  38. else
  39. {
  40. $slide_name = 'slide'.str_repeat('0',2-strlen($i)).$i;
  41. }
  42. $i++;
  43. // add the png to documents
  44. $document_id = add_document($_course,$this->created_dir.'/'.urlencode($file_name),'file',filesize($this->base_work_dir.$this->created_dir.'/'.$file_name),$slide_name);
  45. api_item_property_update($_course,TOOL_DOCUMENT,$document_id,'DocumentAdded',$_SESSION['_uid'],0,0);
  46. // create an html file
  47. $html_file = $file_name.'.html';
  48. $fp = fopen($this->base_work_dir.$this->created_dir.'/'.$html_file, 'w+');
  49. fwrite($fp,
  50. '<html>
  51. <head></head>
  52. <body>
  53. <img src="'.api_get_path(REL_COURSE_PATH).$_course['path'].'/document/'.$this->created_dir.'/'.utf8_encode($file_name).'" />
  54. </body>
  55. </html>');
  56. fclose($fp);
  57. $document_id = add_document($_course,$this->created_dir.'/'.urlencode($html_file),'file',filesize($this->base_work_dir.$this->created_dir.'/'.$html_file),$slide_name);
  58. if ($document_id){
  59. //put the document in item_property update
  60. api_item_property_update($_course,TOOL_DOCUMENT,$document_id,'DocumentAdded',$_SESSION['_uid'],0,0);
  61. $previous = learnpath::add_item(0, $previous, 'document', $document_id, $slide_name, '');
  62. if($this->first_item == 0){
  63. $this->first_item = $previous;
  64. }
  65. }
  66. }
  67. }
  68. function add_command_parameters(){
  69. if(empty($this->slide_width) || empty($this->slide_height))
  70. list($this->slide_width, $this->slide_height) = explode('x',api_get_setting('service_ppt2lp','size'));
  71. 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"';
  72. }
  73. function set_slide_size($width,$height)
  74. {
  75. $this->slide_width = $width;
  76. $this->slide_height = $height;
  77. }
  78. function add_docs_to_visio ($files=array()){
  79. global $_course;
  80. /* Add Files */
  81. foreach($files as $file){
  82. list($slide_name,$file_name) = explode('||',$file); // '||' is used as separator between slide name (with accents) and file name (without accents)
  83. $slide_name = utf8_decode($slide_name); //filename has been written in java, so unicode
  84. $did = add_document($_course, $this->created_dir.'/'.urlencode($file_name), 'file', filesize($this->base_work_dir.$this->created_dir.'/'.$file_name), $slide_name);
  85. if ($did)
  86. api_item_property_update($_course, TOOL_DOCUMENT, $did, 'DocumentAdded', $_SESSION['_uid'], 0, NULL);
  87. }
  88. }
  89. }
  90. ?>