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*/
27APIC::import("org.apicnet.io.OOo.absOOo");
28//APIC::import("org.apicnet.io.OOo.objOOo.OOoCell");
29
30/**
31 * OOoWriter, classe de génération et de modification d'un fichier Writer
32 *
33 * @package
34 * @author apicnet
35 * @copyright Copyright (c) 2004
36 * @version $Id: OOoCalc.php,v 1.3 2005-05-18 11:01:38 mose Exp $
37 * @access public
38 **/
39class OOoCalc extends absOOo {
40
41	var $style;
42	var $STYLNUM = array(
43		'style_family_text' => 1,
44		'style_family_para' => 1,
45		'style_page_style'	=> 1
46	);
47
48	function __construct($dir){
49		parent::__construct();
50		$this->DIRXML = $dir;
51		$this->FILENAME = "content.xml";
52
53		$file = new File($dir."/".$this->FILENAME);
54		if ($file->exists()) {
55			$this->xml = new DOMIT_Document();
56			$this->xml->loadXML($dir."/".$this->FILENAME, false);
57		} else {
58			$this->xml = new DOMIT_Document();
59			$this->create();
60		}
61
62		$this->style = new OOoStyle($this->DIRXML);
63		$this->xml->setDocType("<!DOCTYPE office:document-content PUBLIC \"-//OpenOffice.org//DTD OfficeDocument 1.0//EN\" \"office.dtd\">");
64	}
65
66
67	function create(){
68		$docCalcNode =& $this->xml->createElement("office:document-content");
69		$docCalcNode->setAttribute("xmlns:office", "http://openoffice.org/2000/office");
70		$docCalcNode->setAttribute("xmlns:style", "http://openoffice.org/2000/style");
71		$docCalcNode->setAttribute("xmlns:text", "http://openoffice.org/2000/text");
72		$docCalcNode->setAttribute("xmlns:table", "http://openoffice.org/2000/table");
73		$docCalcNode->setAttribute("xmlns:draw", "http://openoffice.org/2000/drawing");
74		$docCalcNode->setAttribute("xmlns:fo", "http://www.w3.org/1999/XSL/Format");
75		$docCalcNode->setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
76		$docCalcNode->setAttribute("xmlns:number", "http://openoffice.org/2000/datastyle");
77		$docCalcNode->setAttribute("xmlns:svg", "http://www.w3.org/2000/svg");
78		$docCalcNode->setAttribute("xmlns:chart", "http://openoffice.org/2000/chart");
79		$docCalcNode->setAttribute("xmlns:dr3d", "http://openoffice.org/2000/dr3d");
80		$docCalcNode->setAttribute("xmlns:math", "http://www.w3.org/1998/Math/MathML");
81		$docCalcNode->setAttribute("xmlns:form", "http://openoffice.org/2000/form");
82		$docCalcNode->setAttribute("xmlns:script", "http://openoffice.org/2000/script");
83		$docCalcNode->setAttribute("office:class", "spreadsheet");
84		$docCalcNode->setAttribute("office:version", "1.0");
85
86		$docCalcNode->appendChild($this->ChildText("office:script", ""));
87
88		$fontDeclsNode =& $this->xml->createElement("office:font-decls");
89		$fontDeclNode =& $this->xml->createElement("style:font-decl");
90		$fontDeclNode->setAttribute("style:name", "Tahoma1");
91		$fontDeclNode->setAttribute("fo:font-family", "Tahoma");
92		$fontDeclsNode->appendChild($fontDeclNode);
93		$fontDeclNode =& $this->xml->createElement("style:font-decl");
94		$fontDeclNode->setAttribute("style:name", "Andale Sans UI");
95		$fontDeclNode->setAttribute("fo:font-family", "&amp;apos;Andale Sans UI&amp;apos;");
96		$fontDeclNode->setAttribute("style:font-pitch", "variable");
97		$fontDeclsNode->appendChild($fontDeclNode);
98		$fontDeclNode =& $this->xml->createElement("style:font-decl");
99		$fontDeclNode->setAttribute("style:name", "Tahoma");
100		$fontDeclNode->setAttribute("fo:font-family", "Tahoma");
101		$fontDeclNode->setAttribute("style:font-pitch", "variable");
102		$fontDeclsNode->appendChild($fontDeclNode);
103		$fontDeclNode =& $this->xml->createElement("style:font-decl");
104		$fontDeclNode->setAttribute("style:name", "Thorndale");
105		$fontDeclNode->setAttribute("fo:font-family", "Thorndale");
106		$fontDeclNode->setAttribute("style:font-family-generic", "roman");
107		$fontDeclNode->setAttribute("style:font-pitch", "variable");
108		$fontDeclsNode->appendChild($fontDeclNode);
109		$fontDeclNode =& $this->xml->createElement("style:font-decl");
110		$fontDeclNode->setAttribute("style:name", "Arial");
111		$fontDeclNode->setAttribute("fo:font-family", "Arial");
112		$fontDeclNode->setAttribute("style:font-family-generic", "swiss");
113		$fontDeclNode->setAttribute("style:font-pitch", "variable");
114		$fontDeclsNode->appendChild($fontDeclNode);
115		$docCalcNode->appendChild($fontDeclsNode);
116
117
118		$docCalcNode->appendChild($this->ChildText("office:automatic-styles", ""));
119		$docCalcNode->appendChild($this->ChildText("office:body", ""));
120
121		$this->xml->setDocumentElement($docCalcNode);
122		$this->xml->setXMLDeclaration("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
123	}
124
125	function main(){
126		echo $this->toString();
127	}
128
129	function save(){
130		parent::save();
131		$this->style->save();
132	}
133
134	/**
135	 * OOoWriter::addHeader()
136	 *
137	 * @param $argHeager
138	 * @param string $pageName
139	 * @return
140	 **/
141	function addHeader($argHeager, $pageName = "pm1"){
142	//	$this->style->addStyleHeadFoot($argHeager, "Header", $pageName);
143	}
144
145	/**
146	 * OOoWriter::addFooter()
147	 *
148	 * @param $argFooter
149	 * @param string $pageName
150	 * @return
151	 **/
152	function addFooter($argFooter, $pageName = "pm1"){
153	//	$this->style->addStyleHeadFoot($argFooter, "Footer", $pageName);
154	}
155
156
157
158	/**
159	 * OOoTable::colSpan(), méthode de fusion de colonnes. Le numéro des colonnes commence à 0.
160	 *
161	 * @param $argSpan = array(
162	 			"lignSPan"	=> 1,
163	 			"colDeb"	=> 1,
164				"nbCol"		=> 2
165				)
166	 * @return none
167	 **/
168	function colSpan($argSpan){
169
170	}
171
172
173	/**
174	 * OOoTable::rowSpan(), méthode de fusion de lignes. Le numéro des lignes commence à 0.
175	 *
176	 * @param $argSpan = array(
177	 			"lignDeb"	=> 1,
178				"colDeb"	=> 1,
179				"nbLign"	=> 2,
180				"nbCol"		=> 2,
181				)
182	 * @return none
183	 **/
184	function rowSpan($argSpan){
185
186	}
187
188    /**
189     * table::addcellData(), méthode d'ajout de données dans une cellule.
190     *
191     * @param  $argData  = array(
192	 			"data"			=> DATA
193				"img"			=> array(
194						"scr"		=> "E:/_WebDev/www/cOOlWare2/cache/c_projekte.png",
195						"type"		=> "no-repeat",
196						"position"	=> "bottom right"),
197				"marginL"		=> "",
198				"marginR"		=> "",
199				"marginB"		=> "",
200				"marginT"		=> "",
201				"vAlign"		=> "",
202				"bgColor"		=> "",
203				"padding"		=> "",
204				"valueType"		=> "",
205				"borderL"		=> "0.002cm solid #000000",
206				"borderR"		=> "0.002cm solid #000000",
207				"borderB"		=> "0.002cm solid #000000",
208				"borderT"		=> "0.002cm solid #000000",
209				"width"			=> "10"
210				)
211     * @return none
212     */
213	function addcellData($lign, $Col, $argData){
214		echo "/************************traitement des données***********************************/<br>";
215		echo("Col : ".$Col."<br>");
216		echo("lign : ".$lign."<br>");
217
218		$tableNode = & $this->getNode("/office:document-content/office:body/table:table");
219		$addCell   = FALSE;
220		$addLign   = FALSE;
221		$searchRow = 1;
222
223		$tableRowNode = & $this->xml->createElement("table:table-row");
224		$tableRowNode->setAttribute("style:name", "ro1");
225
226		$tableCellNode = & $this->xml->createElement("table:table-cell");
227		$tableCellNode->setAttribute("table:value-type", "float");
228		$tableCellNode->setAttribute("table:value", $argData["DATA"]);
229		$pNode = & $this->xml->createElement("text:p");
230		$textNode = &$this->xml->createTextNode($argData["DATA"]);
231		$pNode->appendChild($textNode);
232		$tableCellNode->appendChild($pNode);
233
234		if ($tableNode->hasChildNodes()) {
235			echo("/**************************il existe des données dans la feuille calc****************/<br>");
236			echo("tableNode->childCount : ".count($tableNode->childNodes)."<br>");
237
238			$currentNode = &$tableNode->firstChild;
239			$nbLign      = count($tableNode->childNodes);
240			$nbCell      = count($currentNode->childNodes);
241
242			if ($lign > $nbLign) $addLign = TRUE;
243			if ($Col > $nbCell) $addCell = TRUE;
244
245			echo("nbLign : ".$nbLign." & addLign : ".$addLign."<br>");
246			echo("nbCell : ".$nbCell." & addCell : ".$addCell."<br>");
247			echo("currentNode : ".($currentNode != NULL)?"NOT NULL<br>":"NULL<br>");
248
249			if (!$addLign) {
250				while ($currentNode != NULL) {
251					if ($searchRow == $lign){
252						if ($addCell){
253							for ($i = $nbCell; $i < $Col-1; $i++) $currentNode->appendChild($this->ChildText("table:table-cell", ""));
254							$currentNode->appendChild($tableCellNode);
255						} else {
256							$currentCellNode =& $currentNode->firstChild;
257							$searchCell = 1;
258							while ($currentCellNode != NULL) {
259								if ($searchCell == $Col) {
260									$parentNodeRepalce = &$currentCellNode->parentNode;
261								    $parentNodeRepalce->replaceChild($tableCellNode, $currentCellNode);
262
263								}
264								$currentCellNode =& $currentCellNode->nextSibling;
265								$searchCell++;
266							}
267						}
268					}
269
270					if ($addCell) for ($i = $nbCell; $i < $Col; $i++) $currentNode->appendChild($this->ChildText("table:table-cell", ""));
271
272					$prevNode = &$currentNode;
273					$currentNode =& $currentNode->nextSibling;
274					$searchRow++;
275				}
276			} else {
277				echo("/******************Ajout des lignes******************/<br>");
278				while ($currentNode != NULL) {
279					if ($addCell){
280						echo("/******************Ajout de cellule******************/<br>");
281						for ($i = $nbCell; $i < $Col; $i++) $currentNode->appendChild($this->ChildText("table:table-cell", ""));
282					}
283					$currentNode =& $currentNode->nextSibling;
284				}
285
286				for ($i = $nbLign; $i < $lign; $i++){
287					$currentRowNode =& $tableRowNode->cloneNode(true);
288					echo("/******************Ajout de ligne******************/<br>");
289					for ($j = 1; (($i==$lign-1)?($j < $Col):($j < $Col+1)); $j++){
290						$currentRowNode->appendChild($this->ChildText("table:table-cell", ""));
291					}
292					$tableNode->appendChild($currentRowNode);
293				}
294				$currentRowNode->appendChild($tableCellNode);
295			}
296
297		} else {
298			echo("/**************************Aucune données dans la feuille calc****************/<br>");
299			for ($i = 0; $i < $lign; $i++){
300				$currentRowNode =& $tableRowNode->cloneNode(true);
301				echo("/******************Ajout de ligne******************/<br>");
302				for ($j = 1; (($i==$lign-1)?($j < $Col):($j < $Col+1)); $j++){
303					$currentRowNode->appendChild($this->ChildText("table:table-cell", ""));
304				}
305				$tableNode->appendChild($currentRowNode);
306			}
307			$currentRowNode->appendChild($tableCellNode);
308		}
309    }
310
311
312	function maxChild(&$node){
313		$currentNode = &$node;
314		$max = 0;
315
316		while ($currentNode != NULL) {
317			if ($max < $currentNode->childCount) $max = $currentNode->childCount;
318			$currentNode =& $currentNode->nextSibling;
319		}
320
321		return $max;
322	}
323
324	 /**
325     * table::addcellData(), méthode d'ajout de données dans une cellule.
326     *
327     * @param  $argData  = array(
328	 			"name"			=> Nom
329				"img"			=> array(
330						"scr"		=> "E:/_WebDev/www/cOOlWare2/cache/c_projekte.png",
331						"type"		=> "no-repeat",
332						"position"	=> "bottom right"),
333				"marginL"		=> "",
334				"marginR"		=> "",
335				"marginB"		=> "",
336				"marginT"		=> "",
337				"vAlign"		=> "",
338				"bgColor"		=> "",
339				"padding"		=> "",
340				"valueType"		=> "",
341				"borderL"		=> "0.002cm solid #000000",
342				"borderR"		=> "0.002cm solid #000000",
343				"borderB"		=> "0.002cm solid #000000",
344				"borderT"		=> "0.002cm solid #000000",
345				"width"			=> "10"
346				)
347     * @return none
348     */
349	function addFeuille($argData = ""){
350		//<table:table table:name="Feuille1" table:style-name="ta1">
351		//<table:table-column table:style-name="co1" table:number-columns-repeated="3" table:default-cell-style-name="Default" />
352
353		$automaticStylesNode =& $this->getNode("/office:document-content/office:automatic-styles");
354		$styleNode =& $this->xml->createElement("style:style");
355		$styleNode->setAttribute("style:name", "ta1");
356		$styleNode->setAttribute("style:family", "table");
357		$styleNode->setAttribute("style:master-page-name", "Default");
358		$propertiesNode =& $this->xml->createElement("style:properties");
359		$propertiesNode->setAttribute("table:display", "true");
360		$styleNode->appendChild($propertiesNode);
361		$automaticStylesNode->appendChild($styleNode);
362
363
364		$bodyNode = & $this->getNode("/office:document-content/office:body");
365		$tableNode = & $this->xml->createElement("table:table");
366		$tableNode->setAttribute("table:name", "1erFeuille");
367		$tableNode->setAttribute("table:style-name", "ta1");
368
369		$bodyNode->appendChild($tableNode);
370
371
372		/*
373<office:automatic-styles>
374	<style:style style:name="co1" style:family="table-column">
375	   <style:properties fo:break-before="auto" style:column-width="2.267cm" />
376	</style:style>
377
378	<style:style style:name="ro1" style:family="table-row">
379	   <style:properties style:row-height="0.453cm" fo:break-before="auto" style:use-optimal-row-height="true" />
380	</style:style>
381
382	<style:style style:name="ta1" style:family="table" style:master-page-name="Default">
383	   <style:properties table:display="true" />
384	</style:style>
385</office:automatic-styles>
386   * */
387	}
388}
389