1<?php
2
3//this script may only be included - so its better to die if called directly.
4if (strpos($_SERVER["SCRIPT_NAME"],basename(__FILE__)) !== false) {
5  header("location: index.php");
6  exit;
7}
8
9
10/*
11This file is part of J4PHP - Ensembles de propriétés et méthodes permettant le developpment rapide d'application web modulaire
12Copyright (c) 2002-2004 @PICNet
13
14This program is free software; you can redistribute it and/or
15modify it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE
16as published by the Free Software Foundation.
17
18This program is distributed in the hope that it will be useful,
19but WITHOUT ANY WARRANTY; without even the implied warranty of
20MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21GNU LESSER GENERAL PUBLIC LICENSE for more details.
22
23You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE
24along with this program; if not, write to the Free Software
25Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
26*/
27
28APIC::import("org.apicnet.io.OOo.*");
29
30
31class OOoDoc extends OOoUtil {
32
33	var $meta;
34	var $content;
35	var $setting;
36	var $manifest;
37	var $fileName;
38	var $dirName;
39	var $XMLTYPE = array('Writer', 'Calc', 'Impress',	'Draw');
40	var $TYPE;
41
42
43	function __construct(){
44		$this->TYPE     = NULL;
45		$this->docExist = FALSE;
46		$this->manifest = NULL;
47		$this->createDirectories();
48	}
49
50
51	function newWriter(){
52		$this->TYPE     = "Writer";
53		$this->docExist = TRUE;
54		$this->meta     = new OOoMeta($this->tmpdir);
55		$this->content  = new OOoWriter($this->tmpdir);
56
57		$this->manifest = new OOoManifest($this->tmpdir);
58		$this->mimeType = new OOoMime($this->tmpdir, $this->TYPE);
59	}
60
61	function newCalc(){
62		$this->TYPE     = "Calc";
63		$this->docExist = TRUE;
64		$this->meta     = new OOoMeta($this->tmpdir);
65	//	$this->style    = new OOoStyle($this->tmpdir);
66		$this->content  = new OOoCalc($this->tmpdir);
67
68		$this->manifest = new OOoManifest($this->tmpdir);
69		$this->mimeType = new OOoMime($this->tmpdir, $this->TYPE);
70	}
71
72	function openWriter($file){
73		$this->TYPE     = "Writer";
74		$allRep         = explode("/", $file);
75		$this->fileName = array_pop($allRep);
76		$this->dirName  = join ("/", $allRep);
77
78		$this->docExist = TRUE;
79
80		$this->unZip($this->tmpdir, $file);
81		$this->meta    = new OOoMeta($this->tmpdir);
82		//$this->style    = new OOoStyle($file);
83		//$this->content  = new OOoWriter($file);
84	}
85
86	function openCalc($file){
87		$this->TYPE     = "Calc";
88
89		$allRep         = explode("/", $file);
90		$this->fileName = array_pop($allRep);
91		$this->dirName  = join ("/", $allRep);
92
93		$this->docExist = TRUE;
94
95		$this->unZip($this->tmpdir, $file);
96		$this->meta    = new OOoMeta($this->tmpdir);
97		//$this->style   = new OOoStyle($file);
98		//$this->content = new OOoCalc($file);
99	}
100
101	function setName($name){
102		$this->fileName  = $name;
103	}
104
105	function save(){
106		if ($this->docExist) {
107			$this->meta->setDate();
108			$this->meta->save();
109
110			$this->content->save();
111
112			if ($this->manifest != NULL){
113				$this->manifest->create($this->TYPE);
114				$this->manifest->save();
115			}
116			$mimeType = new OOoMime($this->tmpdir, $this->TYPE);
117
118			if ($this->fileName != ""){
119				$this->Zip(CACHE_PATH."/".$this->fileName);
120			} else {
121				$this -> ErrorTracker(4, "Vous devez donner un nom a votre fichier", 'save', __FILE__, __LINE__);
122			}
123
124		} else {
125			$this -> ErrorTracker(4, "Aucun document OpenOffice a été créé", 'save', __FILE__, __LINE__);
126		}
127	}
128
129	function close(){
130		$this->delDir($this->tmpdir);
131	}
132
133
134	function download(){
135		$OOoFile = new File(CACHE_PATH."/".$this->fileName);
136		if ($OOoFile->exists()) {
137			$df_size = $OOoFile->length();
138
139			header("Pragma: no-cache");
140			header("Expires: 0");
141			header("Cache-control: private");
142			header("Content-Type: application/vnd.sun.xml.".$this->TYPE);
143			header("Content-Length: ".$df_size);
144			header("Content-Disposition: inline; filename=".$this->fileName);
145
146			$fp = fopen(CACHE_PATH."/".$this->fileName, 'r');
147			rewind($fp);
148			fpassthru($fp); // ** CORRECT **
149			fclose($fp);
150
151			return $fp;
152
153		}
154		return false;
155	}
156
157
158	function mail(){
159	}
160}
161