Subversion Repositories php-qbpwcf

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
23 liveuser 1
<?php
2
/*
3
 
4
ods-php a library to read and write ods files from php.
5
 
6
This library has been forked from eyeOS project and licended under the LGPL3
7
terms available at: http://www.gnu.org/licenses/lgpl-3.0.txt (relicenced
8
with permission of the copyright holders)
9
 
10
Copyright: Juan Lao Tebar (juanlao@eyeos.org) and Jose Carlos Norte (jose@eyeos.org) - 2008 
11
 
12
https://sourceforge.net/projects/ods-php/
13
 
14
*/
15
 
16
class ods {
17
 
18
	#set default date timezone var
19
	var $date_default_timezone;
20
 
21
	var $fonts;
22
	var $styles;
23
	var $sheets;
24
	var $lastElement;
25
	var $fods;
26
	var $currentSheet;
27
	var $currentRow;
28
	var $currentCell;
29
	var $lastRowAtt;
30
	var $repeat;
31
 
32
	function ods() {
33
		$this->styles = array();
34
		$this->fonts = array();
35
		$this->sheets = array();
36
		$this->currentRow = 0;
37
		$this->currentSheet = 0;
38
		$this->currentCell = 0;
39
		$this->repeat = 0;
40
 
41
		#set default date timezone
42
		$this->date_default_timezone="Asia/Taipei";
43
	}
44
 
45
	function parse($data) {
46
		$xml_parser = xml_parser_create(); 
47
		xml_set_object ( $xml_parser, $this );
48
		xml_set_element_handler($xml_parser, "startElement", "endElement");
49
		xml_set_character_data_handler($xml_parser, "characterData");
50
 
51
		xml_parse($xml_parser, $data, strlen($data));
52
 
53
		xml_parser_free($xml_parser);
54
	}
55
 
56
	function array2ods() {
57
		$fontArray = $this->fonts;
58
		$styleArray = $this->styles;
59
		$sheetArray = $this->sheets;
60
		// Header
61
		$string = '<?xml version="1.0" encoding="UTF-8"?><office:document-content xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" xmlns:ooo="http://openoffice.org/2004/office" xmlns:ooow="http://openoffice.org/2004/writer" xmlns:oooc="http://openoffice.org/2004/calc" xmlns:dom="http://www.w3.org/2001/xml-events" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" office:version="1.0">';
62
 
63
		// ToDo: scripts
64
		$string .= '<office:scripts/>';
65
 
66
		// Fonts
67
		$string .= '<office:font-face-decls>';
68
		foreach ($fontArray as $fontName => $fontAttribs) {
69
			$string .= '<style:font-face ';
70
			foreach ($fontAttribs as $attrName => $attrValue) {
71
				$string .= strtolower($attrName) . '="' . $attrValue . '" ';
72
			}
73
			$string .= '/>';
74
		}
75
		$string .= '</office:font-face-decls>';
76
 
77
		// Styles
78
		$string .= '<office:automatic-styles>';
79
		foreach ($styleArray as $styleName => $styleAttribs) {
80
			$string .= '<style:style ';
81
			foreach ($styleAttribs['attrs'] as $attrName => $attrValue) {
82
				$string .= strtolower($attrName) . '="' . $attrValue . '" ';
83
			}
84
			$string .= '>';
85
 
86
			// Subnodes
87
			foreach ($styleAttribs['styles'] as $nodeName => $nodeTree) {
88
				$string .= '<' . $nodeName . ' ';
89
				foreach ($nodeTree as $attrName => $attrValue) {
90
					$string .= strtolower($attrName) . '="' . $attrValue . '" ';
91
				}
92
				$string .= '/>';
93
			}
94
 
95
			$string .= '</style:style>';
96
		}
97
		$string .= '</office:automatic-styles>';
98
 
99
		// Body
100
		$string .= '<office:body>';
101
		$string .= '<office:spreadsheet>';
102
 
103
		#update sheet name to "sheet1~3"
104
		$newSheetArray=array();
105
		foreach($sheetArray as $num=>$value){
106
 
107
			$newSheetArray["sheet".($num+1)]=$value;
108
 
109
			}#foreach
110
 
111
		foreach ($newSheetArray as $tableIndex => $tableContent) {
112
 
113
			#如果分頁沒有內容,則結束foreach
114
			if(count($tableContent)==0 || gettype($tableContent)!="array"){break;}
115
 
116
			$string .= '<table:table table:name="' . $tableIndex . '" table:print="false">';
117
			//$string .= '<office:forms form:automatic-focus="false" form:apply-design-mode="false"/>';
118
 
119
			foreach ($tableContent['rows'] as $rowIndex => $rowContent) {
120
				$string .= '<table:table-row>';
121
 
122
				foreach($rowContent as $cellIndex => $cellContent) {
123
					$string .= '<table:table-cell ';
124
					foreach ($cellContent['attrs'] as $attrName => $attrValue) {
125
						$string .= strtolower($attrName) . '="' . $attrValue . '" ';
126
					}
127
					$string .= '>';
128
 
129
					if (isset($cellContent['value'])) {
130
						$string .= '<text:p>' . $cellContent['value'] . '</text:p>';
131
					}
132
 
133
					$string .= '</table:table-cell>';
134
				}
135
 
136
				$string .= '</table:table-row>';
137
			}
138
 
139
			$string .= '</table:table>';
140
		}
141
 
142
		$string .= '</office:spreadsheet>';
143
		$string .= '</office:body>';
144
 
145
		// Footer
146
		$string .= '</office:document-content>';
147
 
148
		return $string;
149
	}
150
 
151
	function startElement($parser, $tagName, $attrs) {
152
		$cTagName = strtolower($tagName);
153
		if($cTagName == 'style:font-face') {
154
			$this->fonts[$attrs['STYLE:NAME']] = $attrs;
155
		} elseif($cTagName == 'style:style') {
156
			$this->lastElement = $attrs['STYLE:NAME'];
157
			$this->styles[$this->lastElement]['attrs'] = $attrs;
158
		} elseif($cTagName == 'style:table-column-properties' || $cTagName == 'style:table-row-properties' 
159
			|| $cTagName == 'style:table-properties' || $cTagName == 'style:text-properties') {
160
			$this->styles[$this->lastElement]['styles'][$cTagName] = $attrs;
161
		} elseif($cTagName == 'table:table-cell') {
162
			$this->lastElement = $cTagName;
163
			$this->sheets[$this->currentSheet]['rows'][$this->currentRow][$this->currentCell]['attrs'] = $attrs;
164
			if(isset($attrs['TABLE:NUMBER-COLUMNS-REPEATED'])) {
165
				$times = intval($attrs['TABLE:NUMBER-COLUMNS-REPEATED']);
166
				$times--;
167
				for($i=1;$i<=$times;$i++) {
168
					$cnum = $this->currentCell+$i;
169
					$this->sheets[$this->currentSheet]['rows'][$this->currentRow][$cnum]['attrs'] = $attrs;
170
				}
171
				$this->currentCell += $times;
172
				$this->repeat = $times;
173
			}
174
			if(isset($this->lastRowAtt['TABLE:NUMBER-ROWS-REPEATED'])) {
175
				$times = intval($this->lastRowAtt['TABLE:NUMBER-ROWS-REPEATED']);
176
				$times--;
177
				for($i=1;$i<=$times;$i++) {
178
					$cnum = $this->currentRow+$i;
179
					$this->sheets[$this->currentSheet]['rows'][$cnum][$i-1]['attrs'] = $attrs;
180
				}
181
				$this->currentRow += $times;
182
			}
183
		} elseif($cTagName == 'table:table-row') {
184
			$this->lastRowAtt = $attrs;
185
		}
186
	}
187
 
188
	function endElement($parser, $tagName) {
189
		$cTagName = strtolower($tagName);
190
		if($cTagName == 'table:table') {
191
			$this->currentSheet++;
192
			$this->currentRow = 0;
193
		} elseif($cTagName == 'table:table-row') {
194
			$this->currentRow++;
195
			$this->currentCell = 0;
196
		} elseif($cTagName == 'table:table-cell') {
197
			$this->currentCell++;
198
			$this->repeat = 0;
199
		}
200
	}
201
 
202
	function characterData($parser, $data) {
203
		if($this->lastElement == 'table:table-cell') {
204
			$this->sheets[$this->currentSheet]['rows'][$this->currentRow][$this->currentCell]['value'] = $data;
205
			if($this->repeat > 0) {
206
				for($i=0;$i<$this->repeat;$i++) {
207
					$cnum = $this->currentCell - ($i+1);
208
					$this->sheets[$this->currentSheet]['rows'][$this->currentRow][$cnum]['value'] = $data;
209
				}
210
			}
211
		}
212
	}
213
 
214
	function getMeta($lang) {		
215
		date_default_timezone_set($this->date_default_timezone);
216
		$myDate = date('Y-m-j\TH:i:s');
217
		$meta = '<?xml version="1.0" encoding="UTF-8"?>
218
		<office:document-meta xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:ooo="http://openoffice.org/2004/office" office:version="1.0">
219
			<office:meta>
220
				<meta:generator>ods-php</meta:generator>
221
				<meta:creation-date>'.$myDate.'</meta:creation-date>
222
				<dc:date>'.$myDate.'</dc:date>
223
				<dc:language>'.$lang.'</dc:language>
224
				<meta:editing-cycles>2</meta:editing-cycles>
225
				<meta:editing-duration>PT15S</meta:editing-duration>
226
				<meta:user-defined meta:name="Info 1"/>
227
				<meta:user-defined meta:name="Info 2"/>
228
				<meta:user-defined meta:name="Info 3"/>
229
				<meta:user-defined meta:name="Info 4"/>
230
			</office:meta>
231
		</office:document-meta>';
232
		return $meta;
233
	}
234
 
235
	function getStyle() {
236
		return '<?xml version="1.0" encoding="UTF-8"?>
237
			<office:document-styles xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" xmlns:ooo="http://openoffice.org/2004/office" xmlns:ooow="http://openoffice.org/2004/writer" xmlns:oooc="http://openoffice.org/2004/calc" xmlns:dom="http://www.w3.org/2001/xml-events" office:version="1.0"><office:font-face-decls><style:font-face style:name="Liberation Sans" svg:font-family="&apos;Liberation Sans&apos;" style:font-family-generic="swiss" style:font-pitch="variable"/><style:font-face style:name="DejaVu Sans" svg:font-family="&apos;DejaVu Sans&apos;" style:font-family-generic="system" style:font-pitch="variable"/></office:font-face-decls><office:styles><style:default-style style:family="table-cell"><style:table-cell-properties style:decimal-places="2"/><style:paragraph-properties style:tab-stop-distance="1.25cm"/><style:text-properties style:font-name="Liberation Sans" fo:language="es" fo:country="ES" style:font-name-asian="DejaVu Sans" style:language-asian="zxx" style:country-asian="none" style:font-name-complex="DejaVu Sans" style:language-complex="zxx" style:country-complex="none"/></style:default-style><number:number-style style:name="N0"><number:number number:min-integer-digits="1"/>
238
			</number:number-style><number:currency-style style:name="N103P0" style:volatile="true"><number:number number:decimal-places="2" number:min-integer-digits="1" number:grouping="true"/><number:text> </number:text><number:currency-symbol number:language="es" number:country="ES">€</number:currency-symbol></number:currency-style><number:currency-style style:name="N103"><style:text-properties fo:color="#ff0000"/><number:text>-</number:text><number:number number:decimal-places="2" number:min-integer-digits="1" number:grouping="true"/><number:text> </number:text><number:currency-symbol number:language="es" number:country="ES">€</number:currency-symbol><style:map style:condition="value()&gt;=0" style:apply-style-name="N103P0"/></number:currency-style><style:style style:name="Default" style:family="table-cell"/><style:style style:name="Result" style:family="table-cell" style:parent-style-name="Default"><style:text-properties fo:font-style="italic" style:text-underline-style="solid" style:text-underline-width="auto" style:text-underline-color="font-color" fo:font-weight="bold"/></style:style><style:style style:name="Result2" style:family="table-cell" style:parent-style-name="Result" style:data-style-name="N103"/><style:style style:name="Heading" style:family="table-cell" style:parent-style-name="Default"><style:table-cell-properties style:text-align-source="fix" style:repeat-content="false"/><style:paragraph-properties fo:text-align="center"/><style:text-properties fo:font-size="16pt" fo:font-style="italic" fo:font-weight="bold"/></style:style><style:style style:name="Heading1" style:family="table-cell" style:parent-style-name="Heading"><style:table-cell-properties style:rotation-angle="90"/></style:style></office:styles><office:automatic-styles><style:page-layout style:name="pm1"><style:page-layout-properties style:writing-mode="lr-tb"/><style:header-style><style:header-footer-properties fo:min-height="0.751cm" fo:margin-left="0cm" fo:margin-right="0cm" fo:margin-bottom="0.25cm"/></style:header-style><style:footer-style><style:header-footer-properties fo:min-height="0.751cm" fo:margin-left="0cm" fo:margin-right="0cm" fo:margin-top="0.25cm"/>
239
			</style:footer-style></style:page-layout><style:page-layout style:name="pm2"><style:page-layout-properties style:writing-mode="lr-tb"/><style:header-style><style:header-footer-properties fo:min-height="0.751cm" fo:margin-left="0cm" fo:margin-right="0cm" fo:margin-bottom="0.25cm" fo:border="0.088cm solid #000000" fo:padding="0.018cm" fo:background-color="#c0c0c0"><style:background-image/></style:header-footer-properties></style:header-style><style:footer-style><style:header-footer-properties fo:min-height="0.751cm" fo:margin-left="0cm" fo:margin-right="0cm" fo:margin-top="0.25cm" fo:border="0.088cm solid #000000" fo:padding="0.018cm" fo:background-color="#c0c0c0"><style:background-image/></style:header-footer-properties></style:footer-style></style:page-layout></office:automatic-styles><office:master-styles><style:master-page style:name="Default" style:page-layout-name="pm1"><style:header><text:p><text:sheet-name>???</text:sheet-name></text:p></style:header><style:header-left style:display="false"/><style:footer><text:p>Página <text:page-number>1</text:page-number></text:p></style:footer><style:footer-left style:display="false"/></style:master-page><style:master-page style:name="Report" style:page-layout-name="pm2"><style:header><style:region-left><text:p><text:sheet-name>???</text:sheet-name> (<text:title>???</text:title>)</text:p></style:region-left><style:region-right><text:p><text:date style:data-style-name="N2" text:date-value="2008-02-18">18/02/2008</text:date>, <text:time>00:17:06</text:time></text:p></style:region-right></style:header><style:header-left style:display="false"/><style:footer><text:p>Página <text:page-number>1</text:page-number> / <text:page-count>99</text:page-count></text:p></style:footer><style:footer-left style:display="false"/></style:master-page></office:master-styles></office:document-styles>';
240
	}
241
 
242
	function getSettings() {
243
		return '<?xml version="1.0" encoding="UTF-8"?>
244
		<office:document-settings xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0" xmlns:ooo="http://openoffice.org/2004/office" office:version="1.0"><office:settings><config:config-item-set config:name="ooo:view-settings"><config:config-item config:name="VisibleAreaTop" config:type="int">0</config:config-item><config:config-item config:name="VisibleAreaLeft" config:type="int">0</config:config-item><config:config-item config:name="VisibleAreaWidth" config:type="int">2258</config:config-item><config:config-item config:name="VisibleAreaHeight" config:type="int">903</config:config-item><config:config-item-map-indexed config:name="Views"><config:config-item-map-entry><config:config-item config:name="ViewId" config:type="string">View1</config:config-item><config:config-item-map-named config:name="Tables"><config:config-item-map-entry config:name="Hoja1"><config:config-item config:name="CursorPositionX" config:type="int">0</config:config-item><config:config-item config:name="CursorPositionY" config:type="int">1</config:config-item><config:config-item config:name="HorizontalSplitMode" config:type="short">0</config:config-item><config:config-item config:name="VerticalSplitMode" config:type="short">0</config:config-item><config:config-item config:name="HorizontalSplitPosition" config:type="int">0</config:config-item><config:config-item config:name="VerticalSplitPosition" config:type="int">0</config:config-item><config:config-item config:name="ActiveSplitRange" config:type="short">2</config:config-item><config:config-item config:name="PositionLeft" config:type="int">0</config:config-item><config:config-item config:name="PositionRight" config:type="int">0</config:config-item><config:config-item config:name="PositionTop" config:type="int">0</config:config-item><config:config-item config:name="PositionBottom" config:type="int">0</config:config-item></config:config-item-map-entry></config:config-item-map-named><config:config-item config:name="ActiveTable" config:type="string">Hoja1</config:config-item><config:config-item config:name="HorizontalScrollbarWidth" config:type="int">270</config:config-item><config:config-item config:name="ZoomType" config:type="short">0</config:config-item><config:config-item config:name="ZoomValue" config:type="int">100</config:config-item><config:config-item config:name="PageViewZoomValue" config:type="int">60</config:config-item><config:config-item config:name="ShowPageBreakPreview" config:type="boolean">false</config:config-item><config:config-item config:name="ShowZeroValues" config:type="boolean">true</config:config-item><config:config-item config:name="ShowNotes" config:type="boolean">true</config:config-item><config:config-item config:name="ShowGrid" config:type="boolean">true</config:config-item><config:config-item config:name="GridColor" config:type="long">12632256</config:config-item><config:config-item config:name="ShowPageBreaks" config:type="boolean">true</config:config-item><config:config-item config:name="HasColumnRowHeaders" config:type="boolean">true</config:config-item><config:config-item config:name="HasSheetTabs" config:type="boolean">true</config:config-item><config:config-item config:name="IsOutlineSymbolsSet" config:type="boolean">true</config:config-item><config:config-item config:name="IsSnapToRaster" config:type="boolean">false</config:config-item><config:config-item config:name="RasterIsVisible" config:type="boolean">false</config:config-item><config:config-item config:name="RasterResolutionX" config:type="int">1000</config:config-item><config:config-item config:name="RasterResolutionY" config:type="int">1000</config:config-item><config:config-item config:name="RasterSubdivisionX" config:type="int">1</config:config-item>
245
		<config:config-item config:name="RasterSubdivisionY" config:type="int">1</config:config-item><config:config-item config:name="IsRasterAxisSynchronized" config:type="boolean">true</config:config-item></config:config-item-map-entry></config:config-item-map-indexed></config:config-item-set><config:config-item-set config:name="ooo:configuration-settings"><config:config-item config:name="ShowZeroValues" config:type="boolean">true</config:config-item><config:config-item config:name="ShowNotes" config:type="boolean">true</config:config-item><config:config-item config:name="ShowGrid" config:type="boolean">true</config:config-item><config:config-item config:name="GridColor" config:type="long">12632256</config:config-item><config:config-item config:name="ShowPageBreaks" config:type="boolean">true</config:config-item><config:config-item config:name="LinkUpdateMode" config:type="short">3</config:config-item><config:config-item config:name="HasColumnRowHeaders" config:type="boolean">true</config:config-item><config:config-item config:name="HasSheetTabs" config:type="boolean">true</config:config-item><config:config-item config:name="IsOutlineSymbolsSet" config:type="boolean">true</config:config-item><config:config-item config:name="IsSnapToRaster" config:type="boolean">false</config:config-item><config:config-item config:name="RasterIsVisible" config:type="boolean">false</config:config-item><config:config-item config:name="RasterResolutionX" config:type="int">1000</config:config-item><config:config-item config:name="RasterResolutionY" config:type="int">1000</config:config-item><config:config-item config:name="RasterSubdivisionX" config:type="int">1</config:config-item><config:config-item config:name="RasterSubdivisionY" config:type="int">1</config:config-item><config:config-item config:name="IsRasterAxisSynchronized" config:type="boolean">true</config:config-item><config:config-item config:name="AutoCalculate" config:type="boolean">true</config:config-item><config:config-item config:name="PrinterName" config:type="string">Generic Printer</config:config-item><config:config-item config:name="PrinterSetup" config:type="base64Binary">WAH+/0dlbmVyaWMgUHJpbnRlcgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAU0dFTlBSVAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAWAAMAngAAAAAAAAAFAFZUAAAkbQAASm9iRGF0YSAxCnByaW50ZXI9R2VuZXJpYyBQcmludGVyCm9yaWVudGF0aW9uPVBvcnRyYWl0CmNvcGllcz0xCm1hcmdpbmRhanVzdG1lbnQ9MCwwLDAsMApjb2xvcmRlcHRoPTI0CnBzbGV2ZWw9MApjb2xvcmRldmljZT0wClBQRENvbnRleERhdGEKUGFnZVNpemU6TGV0dGVyAAA=</config:config-item><config:config-item config:name="ApplyUserData" config:type="boolean">true</config:config-item><config:config-item config:name="CharacterCompressionType" config:type="short">0</config:config-item><config:config-item config:name="IsKernAsianPunctuation" config:type="boolean">false</config:config-item><config:config-item config:name="SaveVersionOnClose" config:type="boolean">false</config:config-item><config:config-item config:name="UpdateFromTemplate" config:type="boolean">false</config:config-item><config:config-item config:name="AllowPrintJobCancel" config:type="boolean">true</config:config-item><config:config-item config:name="LoadReadonly" config:type="boolean">false</config:config-item></config:config-item-set></office:settings></office:document-settings>';
246
	}
247
 
248
	function getManifest() {
249
		return '<?xml version="1.0" encoding="UTF-8"?>
250
<manifest:manifest xmlns:manifest="urn:oasis:names:tc:opendocument:xmlns:manifest:1.0">
251
 <manifest:file-entry manifest:media-type="application/vnd.oasis.opendocument.spreadsheet" manifest:full-path="/"/>
252
 <manifest:file-entry manifest:media-type="" manifest:full-path="Configurations2/statusbar/"/>
253
 <manifest:file-entry manifest:media-type="" manifest:full-path="Configurations2/accelerator/"/>
254
 <manifest:file-entry manifest:media-type="" manifest:full-path="Configurations2/floater/"/>
255
 <manifest:file-entry manifest:media-type="" manifest:full-path="Configurations2/popupmenu/"/>
256
 <manifest:file-entry manifest:media-type="" manifest:full-path="Configurations2/progressbar/"/>
257
 <manifest:file-entry manifest:media-type="" manifest:full-path="Configurations2/menubar/"/>
258
 <manifest:file-entry manifest:media-type="" manifest:full-path="Configurations2/toolbar/"/>
259
 <manifest:file-entry manifest:media-type="" manifest:full-path="Configurations2/images/Bitmaps/"/>
260
 <manifest:file-entry manifest:media-type="" manifest:full-path="Configurations2/images/"/>
261
 <manifest:file-entry manifest:media-type="application/vnd.sun.xml.ui.configuration" manifest:full-path="Configurations2/"/>
262
 <manifest:file-entry manifest:media-type="text/xml" manifest:full-path="content.xml"/>
263
 <manifest:file-entry manifest:media-type="text/xml" manifest:full-path="styles.xml"/>
264
 <manifest:file-entry manifest:media-type="text/xml" manifest:full-path="meta.xml"/>
265
 <manifest:file-entry manifest:media-type="" manifest:full-path="Thumbnails/"/>
266
 <manifest:file-entry manifest:media-type="text/xml" manifest:full-path="settings.xml"/>
267
</manifest:manifest>';
268
	}
269
 
270
	function addCell($sheet,$row,$cell,$value,$type) {
271
		$this->sheets[$sheet]['rows'][$row][$cell]['attrs'] = array('OFFICE:VALUE-TYPE'=>$type,'OFFICE:VALUE'=>$value);
272
		$this->sheets[$sheet]['rows'][$row][$cell]['value'] = $value;
273
	}
274
 
275
	function editCell($sheet,$row,$cell,$value) {
276
		$this->sheets[$sheet]['rows'][$row][$cell]['attrs']['OFFICE:VALUE'] = $value;
277
		$this->sheets[$sheet]['rows'][$row][$cell]['value'] = $value;
278
	}
279
}
280
 
281
function parseOds($file) {
282
	$tmp = get_tmp_dir();
283
	copy($file,$tmp.'/'.basename($file));
284
	$path = $tmp.'/'.basename($file);
285
	$uid = uniqid();
286
	mkdir($tmp.'/'.$uid);
287
	shell_exec('unzip '.escapeshellarg($path).' -d '.escapeshellarg($tmp.'/'.$uid));
288
	$obj = new ods();
289
	$obj->parse(file_get_contents($tmp.'/'.$uid.'/content.xml'));
290
	return $obj;
291
}
292
 
293
function saveOds($obj,$file) {
294
 
295
	$charset = ini_get('default_charset');
296
	ini_set('default_charset', 'UTF-8');
297
 
298
	#put content to ZipArchive
299
	$document = new ZipArchive();
300
	$document->open($file, ZIPARCHIVE::CREATE);
301
	$document->addFromString('content.xml',$obj->array2ods());
302
	$document->addFromString('mimetype',"application/vnd.oasis.opendocument.spreadsheet");
303
	$document->addFromString('meta.xml',$obj->getMeta('es-ES'));
304
	$document->addFromString('styles.xml',$obj->getStyle());
305
	$document->addFromString('settings.xml',$obj->getSettings());
306
	$document->addFromString('META-INF/manifest.xml',$obj->getManifest());
307
	$document->close();
308
 
309
	#change file Permission if file exist.
310
	if(file_exists($file)){
311
 
312
		chmod($file, 0777);
313
 
314
		}#if end
315
 
316
	ini_set('default_charset',$charset);
317
}
318
 
319
function newOds() {
320
	$content = '<?xml version="1.0" encoding="UTF-8"?>
321
	<office:document-content xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" xmlns:ooo="http://openoffice.org/2004/office" xmlns:ooow="http://openoffice.org/2004/writer" xmlns:oooc="http://openoffice.org/2004/calc" xmlns:dom="http://www.w3.org/2001/xml-events" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" office:version="1.0"><office:scripts/><office:font-face-decls><style:font-face style:name="Liberation Sans" svg:font-family="&apos;Liberation Sans&apos;" style:font-family-generic="swiss" style:font-pitch="variable"/><style:font-face style:name="DejaVu Sans" svg:font-family="&apos;DejaVu Sans&apos;" style:font-family-generic="system" style:font-pitch="variable"/></office:font-face-decls><office:automatic-styles><style:style style:name="co1" style:family="table-column"><style:table-column-properties fo:break-before="auto" style:column-width="2.267cm"/></style:style><style:style style:name="ro1" style:family="table-row"><style:table-row-properties style:row-height="0.453cm" fo:break-before="auto" style:use-optimal-row-height="true"/></style:style><style:style style:name="ta1" style:family="table" style:master-page-name="Default"><style:table-properties table:display="true" style:writing-mode="lr-tb"/></style:style></office:automatic-styles><office:body><office:spreadsheet><table:table table:name="Hoja1" table:style-name="ta1" table:print="false"><office:forms form:automatic-focus="false" form:apply-design-mode="false"/><table:table-column table:style-name="co1" table:default-cell-style-name="Default"/><table:table-row table:style-name="ro1"><table:table-cell/></table:table-row></table:table><table:table table:name="Hoja2" table:style-name="ta1" table:print="false"><table:table-column table:style-name="co1" table:default-cell-style-name="Default"/><table:table-row table:style-name="ro1"><table:table-cell/></table:table-row></table:table><table:table table:name="Hoja3" table:style-name="ta1" table:print="false"><table:table-column table:style-name="co1" table:default-cell-style-name="Default"/><table:table-row table:style-name="ro1"><table:table-cell/></table:table-row></table:table></office:spreadsheet></office:body></office:document-content>';
322
	$obj = new ods();
323
	$obj->parse($content);	
324
	return $obj;
325
}
326
 
327
function get_tmp_dir() {
328
	$path = '';		
329
	if(!function_exists('sys_get_temp_dir')){	    
330
		$path = try_get_temp_dir();
331
	}else{				
332
		$path = sys_get_temp_dir();
333
		if(is_dir($path)){
334
			return $path;	
335
		}else{			
336
			$path = try_get_temp_dir();
337
		}
338
	}
339
	return $path;
340
}
341
 
342
function try_get_temp_dir() {	        
343
    // Try to get from environment variable
344
	if(!empty($_ENV['TMP'])){
345
		$path = realpath($_ENV['TMP']);
346
	}else if(!empty($_ENV['TMPDIR'])){
347
		$path = realpath( $_ENV['TMPDIR'] );
348
	}else if(!empty($_ENV['TEMP'])){
349
		$path = realpath($_ENV['TEMP']);
350
	}
351
	// Detect by creating a temporary file
352
	else{
353
		// Try to use system's temporary directory
354
		// as random name shouldn't exist
355
		$temp_file = tempnam(md5(uniqid(rand(),TRUE)),'');
356
		if ($temp_file){
357
			$temp_dir = realpath(dirname($temp_file));
358
			unlink($temp_file);
359
			$path = $temp_dir;
360
		}else{
361
			return "/tmp";
362
		}
363
	}	
364
	return $path;
365
}
366
 
367
?>