Subversion Repositories php-qbpwcf

Rev

Rev 226 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
3 liveuser 1
<?php
2
 
3
/*
4
 
5
	QBPWCF, Quick Build PHP website Component base on Fedora Linux.
6
    Copyright (C) 2015~2024 Min-Jhin,Chen
7
 
8
    This file is part of QBPWCF.
9
 
10
    QBPWCF is free software: you can redistribute it and/or modify
11
    it under the terms of the GNU General Public License as published by
12
    the Free Software Foundation, either version 3 of the License, or
13
    (at your option) any later version.
14
 
15
    QBPWCF is distributed in the hope that it will be useful,
16
    but WITHOUT ANY WARRANTY; without even the implied warranty of
17
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
    GNU General Public License for more details.
19
 
20
    You should have received a copy of the GNU General Public License
21
    along with QBPWCF.  If not, see <http://www.gnu.org/licenses/>.
22
 
23
*/
24
namespace qbpwcf;
25
 
26
/*
27
類別說明:
28
跟open document有關的類別.
29
備註:
30
無.
31
*/
32
class od{
33
 
34
	/*
35
	#函式說明:
36
	#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
37
	#回傳結果:
38
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
39
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
40
	#$result["function"],當前執行的函式名稱.
41
	#必填參數:
42
	#$method,物件,為物件實體或類別名稱,會自動置入該參數.
43
	#$arguments,陣列,為呼叫方法時所用的參數.
44
	#參考資料:
45
	#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
46
	*/
47
	public function __call($method,$arguments){
48
 
49
		#取得當前執行的函式
50
		$result["function"]=__FUNCTION__;
51
 
52
		#設置執行不正常
53
		$result["status"]="false";
54
 
55
		#設置執行錯誤
56
		$result["error"][]=__NAMESPACE__ ."/".$method."() 不存在!";
57
 
58
		#設置所丟入的參數
59
		$result["error"][]=$arguments;
60
 
61
		#回傳結果
62
		return $result;
63
 
64
		}#function __call end
65
 
66
	/*
67
	#函式說明:
68
	#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
69
	#回傳結果:
70
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
71
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
72
	#$result["function"],當前執行的函式名稱.
73
	#必填參數:
74
	#$method,物件,為物件實體或類別名稱,會自動置入該參數.
75
	#$arguments,陣列,為呼叫方法時所用的參數.
76
	#參考資料:
77
	#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
78
	*/
79
	public static function __callStatic($method,$arguments){
80
 
81
		#取得當前執行的函式
82
		$result["function"]=__FUNCTION__;
83
 
84
		#設置執行不正常
85
		$result["status"]="false";
86
 
87
		#設置執行錯誤
88
		$result["error"][]="欲呼叫的". __NAMESPACE__ ."/".$method."() 不存在!";
89
 
90
		#設置所丟入的參數
91
		$result["error"][]=$arguments;
92
 
93
		#回傳結果
94
		return $result;
95
 
96
		}#function __callStatic end	
97
 
98
	/*
99
	#函式說明:
100
	#匯入phpodt函式庫的函式
101
	#回傳結果:
102
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
103
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
104
	#$result["function"],當前執行的函式名稱.
105
	#必填參數:
106
	#無
107
	#可省略參數:
108
	#無
109
	*/
110
	function importOdtLib(){
111
 
112
		#取得當前執行的函式
113
		$result["function"]=__FUNCTION__;
114
 
115
		#設定 phpodt lib 的路徑
116
		$phpOdtLibPath="lib/phpodt-0.3.3/phpodt.php";
117
 
118
		#檢查要匯入的套件是否存在
119
		#涵式說明:檢查多個檔案與資料夾是否存在.
120
		#回傳的結果:
121
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
122
		#$result["error"],錯誤訊息陣列.
123
		#$resutl["function"],當前執行的涵式名稱.
124
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
125
		#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
126
		#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱。
127
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
128
		#必填參數:
129
		#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
130
		$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($phpOdtLibPath);
131
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
132
		$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=__FILE__;
133
		#可省略參數
134
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
135
		#$conf["disableWebSearch"]="false";
136
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
137
		#$conf["userDir"]="true";
138
		#參考資料來源:
139
		#http://php.net/manual/en/function.file-exists.php
140
		#http://php.net/manual/en/control-structures.foreach.php
141
		#備註:
142
		#函數file_exists檢查的路徑為檔案系統的路徑
143
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
144
		unset($conf["fileAccess::checkMultiFileExist"]);
145
 
146
		#如果檢查檔案是否存在失敗
147
		if($checkMultiFileExist["status"]=="false"){
148
 
149
			#設置錯誤訊息
150
			$result["error"]=$checkMultiFileExist;
151
 
152
			#設置執行不正常
153
			$result["status"]="false";
154
 
155
			#回傳結果
156
			return $result;
157
 
158
			}#if end
159
 
160
		#如果檔案不存在
161
		if($checkMultiFileExist["allExist"]=="false"){
162
 
163
			#設置錯誤訊息
164
			$result["error"]=$checkMultiFileExist;
165
 
166
			#設置執行不正常
167
			$result["status"]="false";
168
 
169
			#回傳結果
170
			return $result;
171
 
172
			}#if end		
173
 
174
		#匯入 phpodt 套件
175
		include($phpOdtLibPath);
176
 
177
		#設置執行正常
178
		$result["status"]="true";			
179
 
180
		#回傳結果
181
		return $result;
182
 
183
		}#function importOdtLib end
184
 
185
	/*
186
	#函式說明:
187
	#展示建立odt檔案的功能,會產生名稱為"od::demoOdt.odt"的檔案
188
	#回傳結果:
189
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
190
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
191
	#$result["function"],當前執行的函式名稱.
192
	#$result["content"],建立的ods檔案路徑與名稱.
193
	#必填參數:
194
	#無
195
	#可省略參數:
196
	#無
197
	#參考資料:
198
	#http://php-odt.sourceforge.net/ 
199
	*/
200
	function demoOdt(){
201
 
202
		#取得當前執行的函式
203
		$result["function"]=__FUNCTION__;	
204
 
205
		/*
206
		#函式說明:
207
		#匯入phpodt函式庫的函式
208
		#回傳結果:
209
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
210
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
211
		#$result["function"],當前執行的函式名稱.
212
		#必填參數:
213
		#無
214
		#可省略參數:
215
		#無
216
		*/
217
		$importLib=od::importOdtLib();
218
 
219
		#如果匯入 phpodt 函式庫失敗
220
		if($importLib["status"]=="false"){
221
 
222
			#設置錯誤訊息
223
			$result["error"]=$importLib;
224
 
225
			#設置執行不正常
226
			$result["status"]="false";
227
 
228
			#回傳結果
229
			return $result;
230
 
231
			}#if end
232
 
233
		#DEMO
234
		$odt=\ODT::getInstance();
235
		$p=new \Paragraph();
236
		$p->addText('Hello World!!');
237
		$odt->output('odT/demoOdt.odt');
238
 
239
		#取得檔案位置
240
		$result["content"]="odT/demoOdt.odt";
241
 
242
		#設置執行正常
243
		$result["status"]="true";
244
 
245
		#回傳結果
246
		return $result;
247
 
248
		}#function demoOdt
249
 
250
	/*
251
	#函式說明:
252
	#匯入phpods函式庫的函式
253
	#回傳結果:
254
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
255
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
256
	#$result["function"],當前執行的函式名稱.
257
	#必填參數:
258
	#無
259
	#可省略參數:
260
	#無
261
	*/
262
	function importOdsLib(){
263
 
264
		#取得當前執行的函式
265
		$result["function"]=__FUNCTION__;
266
 
267
		#設定 phpods lib 的路徑
268
		$phpOdsLibPath="lib/ods-php-0.1rc1/ods.php";
269
 
270
		#檢查要匯入的套件是否存在
271
		#涵式說明:檢查多個檔案與資料夾是否存在.
272
		#回傳的結果:
273
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
274
		#$result["error"],錯誤訊息陣列.
275
		#$resutl["function"],當前執行的涵式名稱.
276
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
277
		#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
278
		#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱。
279
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
280
		#必填參數:
281
		#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
282
		$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($phpOdsLibPath);
283
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
284
		$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=__FILE__;
285
		#可省略參數
286
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
287
		#$conf["disableWebSearch"]="false";
288
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
289
		#$conf["userDir"]="true";
290
		#參考資料來源:
291
		#http://php.net/manual/en/function.file-exists.php
292
		#http://php.net/manual/en/control-structures.foreach.php
293
		#備註:
294
		#函數file_exists檢查的路徑為檔案系統的路徑
295
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
296
		unset($conf["fileAccess::checkMultiFileExist"]);
297
 
298
		#如果檢查檔案是否存在失敗
299
		if($checkMultiFileExist["status"]=="false"){
300
 
301
			#設置錯誤訊息
302
			$result["error"]=$checkMultiFileExist;
303
 
304
			#設置執行不正常
305
			$result["status"]="false";
306
 
307
			#回傳結果
308
			return $result;
309
 
310
			}#if end
311
 
312
		#如果檔案不存在
313
		if($checkMultiFileExist["allExist"]=="false"){
314
 
315
			#設置錯誤訊息
316
			$result["error"]=$checkMultiFileExist;
317
 
318
			#設置執行不正常
319
			$result["status"]="false";
320
 
321
			#回傳結果
322
			return $result;
323
 
324
			}#if end		
325
 
326
		#匯入 phpodt 套件
327
		include($phpOdsLibPath);
328
 
329
		#設置執行正常
330
		$result["status"]="true";			
331
 
332
		#回傳結果
333
		return $result;
334
 
335
		}#function importOdsLib end	
336
 
337
	/*
338
	#函式說明:
339
	#展示建立ods檔案的功能,會出現檔案名稱為'od::demoOdf.ods'的檔案.
340
	#回傳結果:
341
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
342
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
343
	#$result["function"],當前執行的函式名稱.
344
	#$result["content"],建立的ods檔案路徑與名稱.
345
	#必填參數:
346
	#無
347
	#可省略參數:
348
	#無
349
	#參考資料:
350
	#https://sourceforge.net/projects/ods-php/?source=typ_redirect
351
	*/
352
	function demoOds(){
353
 
354
		/*
355
		#函式說明:
356
		#匯入phpods函式庫的函式
357
		#回傳結果:
358
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
359
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
360
		#$result["function"],當前執行的函式名稱.
361
		#必填參數:
362
		#無
363
		#可省略參數:
364
		#無
365
		*/
366
		$importOdsLib=od::importOdsLib();
367
 
368
		#如果載入 php ods lib 失敗
369
		if($importOdsLib["status"]=="false"){				
370
 
371
			#設置錯誤訊息
372
			$result["error"]=$importLib;
373
 
374
			#設置執行不正常
375
			$result["status"]="false";
376
 
377
			#回傳結果
378
			return $result;			
379
 
380
			}#if end
381
 
382
		#create a new ods file
383
		$object=\newOds(); 
384
 
385
		#add a cell to sheet 0, row 0, cell 0, with value 1 and type float
386
		$object->addCell(0,0,0,1,'float');
387
 
388
		#add a cell to sheet 0, row 0, cell 1, with value 1 and type float
389
		$object->addCell(0,0,1,2,'float'); 
390
 
391
		#add a cell to sheet 0, row 1, cell 0, with value 1 and type float
392
		$object->addCell(0,1,0,1,'float'); 
393
 
394
		#add a cell to sheet 0, row 1, cell 1, with value 1 and type float
395
		$object->addCell(0,1,1,2,'float');
396
 
397
		#save the object to a ods file
398
		saveOds($object,'odT/demoOdf.ods'); 
399
 
400
		#取得檔案路徑
401
		$result["content"]="odT/demoOdf.ods";
402
 
403
		#設置執行正常
404
		$result["status"]="true";
405
 
406
		#回傳結果
407
		return $result;
408
 
409
		}#function demoOds end
410
 
411
	/*
412
	#函式說明:
413
	#建立ods檔案
414
	#回傳結果:
415
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
416
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
417
	#$result["function"],當前執行的函式名稱.
418
	#$result["content"],建立的ods檔案路徑與名稱.
419
	#必填參數:
420
	#$conf["filePathAndName"],字串,ods檔案要存放的地方,副檔名".ods"會自動補上.
421
	$conf["filePathAndName"]="";
422
	#$conf["content"],字串陣列,要放在ods檔案裡面各sheet的內容,$conf["content"][tab][row][col]=array("Hello!","string");為第tab+1個分頁第row+1列第col+1欄的內容為"Hello!",型態為"string",型態未指定的話,則預設為"string".
423
	$conf["content"]=;
424
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
425
	$conf["fileArgu"]=__FILE__;
426
	#可省略參數:
427
	#無
428
	#參考資料:
429
	#https://sourceforge.net/projects/ods-php/?source=typ_redirect
430
	*/
431
	function createOds(&$conf){
432
 
433
		#初始化要回傳的結果
434
		$result=array();
435
 
436
		#取得當前執行的函數
437
		$result["function"]=__FUNCTION__;
438
 
439
		#如果 $conf 不為陣列
440
		if(gettype($conf)!="array"){
441
 
442
			#設置執行失敗
443
			$result["status"]="false";
444
 
445
			#設置執行錯誤訊息
446
			$result["error"][]="\$conf變數須為陣列形態";
447
 
448
			#如果傳入的參數為 null
449
			if($conf==null){
450
 
451
				#設置執行錯誤訊息
452
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
453
 
454
				}#if end
455
 
456
			#回傳結果
457
			return $result;
458
 
459
			}#if end
460
 
461
		#檢查參數
462
		#函式說明:
463
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
464
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
465
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
466
		#$result["function"],當前執行的函式名稱.
467
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
468
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
469
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
470
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
471
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
472
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
473
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
474
		#必填寫的參數:
475
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
476
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
477
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
478
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("filePathAndName","content","fileArgu");
479
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double"); 
480
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","array","string");
481
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
482
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
483
		#可以省略的參數:
484
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
485
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
486
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
487
		#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("alt","class");
488
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double"); 
489
		#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
490
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
491
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("","");
492
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
493
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array();
494
		#參考資料來源:
495
		#array_keys=>http://php.net/manual/en/function.array-keys.php
496
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
497
		unset($conf["variableCheck::checkArguments"]);
498
 
499
		#如果檢查失敗
500
		if($checkResult["status"]=="false"){
501
 
502
			#設置錯誤狀態
503
			$result["status"]="false";
504
 
505
			#設置錯誤提示
506
			$result["error"]=$checkResult;
507
 
508
			#回傳結果
509
			return $result;
510
 
511
			}#if end
512
 
513
		#如果檢查不通過
514
		if($checkResult["passed"]=="false"){
515
 
516
			#設置錯誤狀態
517
			$result["status"]="false";
518
 
519
			#設置錯誤提示
520
			$result["error"]=$checkResult;
521
 
522
			#回傳結果
523
			return $result;
524
 
525
			}#if end
526
 
527
		/*
528
		#函式說明:
529
		#匯入phpods函式庫的函式
530
		#回傳結果:
531
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
532
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
533
		#$result["function"],當前執行的函式名稱.
534
		#必填參數:
535
		#無
536
		#可省略參數:
537
		#無
538
		*/
539
		$importOdsLib=od::importOdsLib();
540
 
541
		#create a new ods file
542
		$object=\newOds(); 
543
 
544
		#針對每個分頁
545
		foreach($conf["content"] as $tabName=>$tabContent){
546
 
547
			#如果 $tabContent 不為陣列或元素數量為0
548
			if(gettype($tabContent)!="array" || count($tabContent)==0){
549
 
550
				#結束foreach end
551
				break;
552
 
553
				}#if end
554
 
555
			#針對每個列
556
			foreach($tabContent as $rowName=>$rowContent){
557
 
558
				#如果 $rowContent 不為陣列或元素數量為0
559
				if(gettype($rowContent)!="array" || count($rowContent)==0){
560
 
561
					#結束foreach end
562
					break;
563
 
564
					}#if end
565
 
566
				#針對每個行
567
				foreach($rowContent as $colName=>$colContent){
568
 
569
					#如果 $colContent 不為陣列或元素數量為0
570
					if(gettype($colContent)!="array" || count($colContent)==0){
571
 
572
						#結束foreach end
573
						break;
574
 
575
						}#if end
576
 
577
					#針對每個欄位的內容
578
					for($i=0;$i<2;$i++){
579
 
580
						#如果內容元素不存在
581
						if(!isset($colContent[$i])){
582
 
583
							#如果是數值
584
							if($i==0){
585
 
586
								#設為空字串
587
								$colContent[$i]="";
588
 
589
								}#if end
590
 
591
							#反之如果是形態
592
							else if($i==1){
593
 
594
								#設為字串
595
								$colContent[$i]="string";
596
 
597
								}#if end
598
 
599
							}#if end
600
 
601
						}#for end
602
 
603
					#add a cell to sheet $tabName, row $rowName, cell $colName, with value $colContent[0] and type $colContent[1]
604
					$object->addCell($tabName,$rowName,$colName,$colContent[0],$colContent[1]);
605
 
606
					}#foreach end
607
 
608
				}#foreache end
609
 
610
			}#foreach end
611
 
612
		#確保路徑
613
		#涵式說明:
614
		#確保路徑存在.
615
		#回傳的結果:
616
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
617
		#$result["error"],錯誤訊息陣列.
618
		#$resutl["function"],當前執行的涵式名稱.
619
		#必填的參數:
620
		#$conf["path"],要檢查的路徑
621
		$conf["fileAccess::validatePath"]["path"]=$conf["filePathAndName"];		
622
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
623
		$conf["fileAccess::validatePath"]["fileArgu"]=$conf["fileArgu"];
624
		#可省略參數:
625
		#$conf["haveFileName"],字串,"true"代表有$conf["path"]檔案名稱,"false"代表$conf["path"]為純路徑,預設為"false".
626
		$conf["fileAccess::validatePath"]["haveFileName"]="true";
627
		#$conf["dirPermission"],字串,新建資料夾的權限設定,預設爲0770,亦即擁有者,同群組者可以讀,寫,存取,其他人僅能存取.
628
		#$conf["dirPermission"]="";
629
		$validatePath=fileAccess::validatePath($conf["fileAccess::validatePath"]);
630
		unset($conf["fileAccess::validatePath"]);
631
 
632
		#如果確保路徑失敗
633
		if($validatePath["status"]=="false"){
634
 
635
			#設置錯誤狀態
636
			$result["status"]="false";
637
 
638
			#設置錯誤提示
639
			$result["error"]=$validatePath;
640
 
641
			#回傳結果
642
			return $result;
643
 
644
			}#if end
645
 
646
		#save the object to a ods file
647
		saveOds($object,$conf["filePathAndName"].".ods"); 
648
 
649
		#取得ods檔案的路徑
650
		$result["content"]=$conf["filePathAndName"].".ods";
651
 
652
		#設置執行正常
653
		$result["status"]="true";
654
 
655
		#回傳結果
656
		return $result;
657
 
658
		}#function createOds end
659
 
660
	/*
661
	#函式說明:
662
	#建立odt檔案
663
	#回傳結果:
664
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
665
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
666
	#$result["function"],當前執行的函式名稱.
667
	#$result["content"],建立的ods檔案路徑與名稱.
668
	#必填參數:
669
	#$conf["filePathAndName"],字串,odt檔案要存放的地方,副檔名".odt"會自動補上.
670
	$conf["filePathAndName"]="";
671
	#$conf["content"],字串陣列,要放在odt檔案裡面的內容,每個元素的內容代表一個段落.
672
	$conf["content"]=array();
673
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
674
	$conf["fileArgu"]=__FILE__;
675
	#可省略參數:
676
	#無
677
	#參考資料:
678
	#https://sourceforge.net/projects/ods-php/?source=typ_redirect
679
	*/
680
	function createOdt(&$conf){
681
 
682
		#初始化要回傳的結果
683
		$result=array();
684
 
685
		#取得當前執行的函數名稱
686
		$result["function"]=__FUNCTION__;
687
 
688
		#如果沒有參數
689
		if(func_num_args()==0){
690
 
691
			#設置執行失敗
692
			$result["status"]="false";
693
 
694
			#設置執行錯誤訊息
695
			$result["error"]="函數".$result["function"]."需要參數";
696
 
697
			#回傳結果
698
			return $result;
699
 
700
			}#if end
701
 
702
		#取得參數
703
		$result["argu"]=$conf;
704
 
705
		#如果 $conf 不為陣列
706
		if(gettype($conf)!="array"){
707
 
708
			#設置執行失敗
709
			$result["status"]="false";
710
 
711
			#設置執行錯誤訊息
712
			$result["error"][]="\$conf變數須為陣列形態";
713
 
714
			#如果傳入的參數為 null
715
			if($conf==null){
716
 
717
				#設置執行錯誤訊息
718
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
719
 
720
				}#if end
721
 
722
			#回傳結果
723
			return $result;
724
 
725
			}#if end
726
 
727
		#檢查參數
728
		#函式說明:
729
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
730
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
731
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
732
		#$result["function"],當前執行的函式名稱.
733
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
734
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
735
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
736
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
737
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
738
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
739
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
740
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
741
		#必填寫的參數:
742
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
743
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
744
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
745
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("filePathAndName","content","fileArgu");
746
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
747
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","array","string");
748
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
749
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
750
		#可以省略的參數:
751
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
752
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="true";
753
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
754
		$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("filePathAndName");
755
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
756
		#$conf["canBeEmpty"]=array();
757
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
758
		#$conf["skipableVariableCanNotBeEmpty"]=array();
759
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
760
		#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("liId");
761
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double"); 
762
		#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array");
763
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
764
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("\$conf[\"liName\"]");
765
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
766
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("liName","liContnet","liId");
767
		#參考資料來源:
768
		#array_keys=>http://php.net/manual/en/function.array-keys.php
769
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
770
		unset($conf["variableCheck::checkArguments"]);
771
 
772
		#如果檢查參數失敗
773
		if($checkArguments["status"]=="false"){
774
 
775
			#設置執行失敗
776
			$result["status"]="false";
777
 
778
			#設置執行錯誤訊息
779
			$result["error"]=$checkArguments;
780
 
781
			#回傳結果
782
			return $result;
783
 
784
			}#if end
785
 
786
		#如果檢查參數不通過
787
		if($checkArguments["passed"]=="false"){
788
 
789
			#設置執行失敗
790
			$result["status"]="false";
791
 
792
			#設置執行錯誤訊息
793
			$result["error"]=$checkArguments;
794
 
795
			#回傳結果
796
			return $result;
797
 
798
			}#if end	
799
 
800
		#函式說明:
801
		#匯入phpodt函式庫的函式
802
		#回傳結果:
803
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
804
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
805
		#$result["function"],當前執行的函式名稱.
806
		#必填參數:
807
		#無
808
		#可省略參數:
809
		#無
810
		$importLib=od::importOdtLib();
811
 
812
		#如果匯入 phpodt 函式庫失敗
813
		if($importLib["status"]=="false"){
814
 
815
			#設置錯誤訊息
816
			$result["error"]=$importLib;
817
 
818
			#設置執行不正常
819
			$result["status"]="false";
820
 
821
			#回傳結果
822
			return $result;
823
 
824
			}#if end
825
 
826
		#建立實體
827
		$odt=\ODT::getInstance();
828
 
829
		#針對 $conf["content"] 的每個元素
830
		foreach($conf["content"] as $pKey=>$pVal){
831
 
832
			#新增段落
833
			$pKey=new \Paragraph();
834
 
835
			#設置內容
836
			$pKey->addText($pVal);
837
 
838
			}#foreach end
839
 
840
		#輸出置檔案
841
		$odt->output($conf["filePathAndName"].".odt");
842
 
843
		#取得檔案位置
844
		$result["content"]=$conf["filePathAndName"].".odt";
845
 
846
		#設置執行正常
847
		$result["status"]="true";
848
 
849
		#回傳結果
850
		return $result;
851
 
852
		}#function createOdt end
853
 
854
	}#class od end
855
 
856
?>