Subversion Repositories php-qbpwcf

Rev

Rev 3 | Go to most recent revision | Details | Compare with Previous | 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.
226 liveuser 6
    Copyright (C) 2014~2025 MIN ZHI, CHEN
3 liveuser 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{
226 liveuser 33
 
3 liveuser 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){
226 liveuser 48
 
3 liveuser 49
		#取得當前執行的函式
50
		$result["function"]=__FUNCTION__;
226 liveuser 51
 
3 liveuser 52
		#設置執行不正常
53
		$result["status"]="false";
226 liveuser 54
 
3 liveuser 55
		#設置執行錯誤
56
		$result["error"][]=__NAMESPACE__ ."/".$method."() 不存在!";
226 liveuser 57
 
3 liveuser 58
		#設置所丟入的參數
59
		$result["error"][]=$arguments;
226 liveuser 60
 
3 liveuser 61
		#回傳結果
62
		return $result;
226 liveuser 63
 
3 liveuser 64
		}#function __call end
226 liveuser 65
 
3 liveuser 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){
226 liveuser 80
 
3 liveuser 81
		#取得當前執行的函式
82
		$result["function"]=__FUNCTION__;
226 liveuser 83
 
3 liveuser 84
		#設置執行不正常
85
		$result["status"]="false";
226 liveuser 86
 
3 liveuser 87
		#設置執行錯誤
88
		$result["error"][]="欲呼叫的". __NAMESPACE__ ."/".$method."() 不存在!";
226 liveuser 89
 
3 liveuser 90
		#設置所丟入的參數
91
		$result["error"][]=$arguments;
226 liveuser 92
 
3 liveuser 93
		#回傳結果
94
		return $result;
226 liveuser 95
 
96
		}#function __callStatic end
97
 
3 liveuser 98
	/*
99
	#函式說明:
100
	#匯入phpodt函式庫的函式
101
	#回傳結果:
102
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
103
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
104
	#$result["function"],當前執行的函式名稱.
105
	#必填參數:
106
	#無
107
	#可省略參數:
108
	#無
109
	*/
110
	function importOdtLib(){
226 liveuser 111
 
3 liveuser 112
		#取得當前執行的函式
113
		$result["function"]=__FUNCTION__;
226 liveuser 114
 
3 liveuser 115
		#設定 phpodt lib 的路徑
116
		$phpOdtLibPath="lib/phpodt-0.3.3/phpodt.php";
226 liveuser 117
 
3 liveuser 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"]);
226 liveuser 145
 
3 liveuser 146
		#如果檢查檔案是否存在失敗
147
		if($checkMultiFileExist["status"]=="false"){
226 liveuser 148
 
3 liveuser 149
			#設置錯誤訊息
150
			$result["error"]=$checkMultiFileExist;
226 liveuser 151
 
3 liveuser 152
			#設置執行不正常
153
			$result["status"]="false";
226 liveuser 154
 
3 liveuser 155
			#回傳結果
156
			return $result;
226 liveuser 157
 
3 liveuser 158
			}#if end
226 liveuser 159
 
3 liveuser 160
		#如果檔案不存在
161
		if($checkMultiFileExist["allExist"]=="false"){
226 liveuser 162
 
3 liveuser 163
			#設置錯誤訊息
164
			$result["error"]=$checkMultiFileExist;
226 liveuser 165
 
3 liveuser 166
			#設置執行不正常
167
			$result["status"]="false";
226 liveuser 168
 
3 liveuser 169
			#回傳結果
170
			return $result;
226 liveuser 171
 
172
			}#if end
173
 
3 liveuser 174
		#匯入 phpodt 套件
175
		include($phpOdtLibPath);
226 liveuser 176
 
3 liveuser 177
		#設置執行正常
226 liveuser 178
		$result["status"]="true";
179
 
3 liveuser 180
		#回傳結果
181
		return $result;
226 liveuser 182
 
3 liveuser 183
		}#function importOdtLib end
226 liveuser 184
 
3 liveuser 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
	#參考資料:
226 liveuser 198
	#http://php-odt.sourceforge.net/
3 liveuser 199
	*/
200
	function demoOdt(){
226 liveuser 201
 
3 liveuser 202
		#取得當前執行的函式
226 liveuser 203
		$result["function"]=__FUNCTION__;
204
 
3 liveuser 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();
226 liveuser 218
 
3 liveuser 219
		#如果匯入 phpodt 函式庫失敗
220
		if($importLib["status"]=="false"){
226 liveuser 221
 
3 liveuser 222
			#設置錯誤訊息
223
			$result["error"]=$importLib;
226 liveuser 224
 
3 liveuser 225
			#設置執行不正常
226
			$result["status"]="false";
226 liveuser 227
 
3 liveuser 228
			#回傳結果
229
			return $result;
226 liveuser 230
 
3 liveuser 231
			}#if end
226 liveuser 232
 
3 liveuser 233
		#DEMO
234
		$odt=\ODT::getInstance();
235
		$p=new \Paragraph();
236
		$p->addText('Hello World!!');
237
		$odt->output('odT/demoOdt.odt');
226 liveuser 238
 
3 liveuser 239
		#取得檔案位置
240
		$result["content"]="odT/demoOdt.odt";
226 liveuser 241
 
3 liveuser 242
		#設置執行正常
243
		$result["status"]="true";
226 liveuser 244
 
3 liveuser 245
		#回傳結果
246
		return $result;
226 liveuser 247
 
3 liveuser 248
		}#function demoOdt
226 liveuser 249
 
3 liveuser 250
	/*
251
	#函式說明:
252
	#匯入phpods函式庫的函式
253
	#回傳結果:
254
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
255
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
256
	#$result["function"],當前執行的函式名稱.
257
	#必填參數:
258
	#無
259
	#可省略參數:
260
	#無
261
	*/
262
	function importOdsLib(){
226 liveuser 263
 
3 liveuser 264
		#取得當前執行的函式
265
		$result["function"]=__FUNCTION__;
226 liveuser 266
 
3 liveuser 267
		#設定 phpods lib 的路徑
268
		$phpOdsLibPath="lib/ods-php-0.1rc1/ods.php";
226 liveuser 269
 
3 liveuser 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"]);
226 liveuser 297
 
3 liveuser 298
		#如果檢查檔案是否存在失敗
299
		if($checkMultiFileExist["status"]=="false"){
226 liveuser 300
 
3 liveuser 301
			#設置錯誤訊息
302
			$result["error"]=$checkMultiFileExist;
226 liveuser 303
 
3 liveuser 304
			#設置執行不正常
305
			$result["status"]="false";
226 liveuser 306
 
3 liveuser 307
			#回傳結果
308
			return $result;
226 liveuser 309
 
3 liveuser 310
			}#if end
226 liveuser 311
 
3 liveuser 312
		#如果檔案不存在
313
		if($checkMultiFileExist["allExist"]=="false"){
226 liveuser 314
 
3 liveuser 315
			#設置錯誤訊息
316
			$result["error"]=$checkMultiFileExist;
226 liveuser 317
 
3 liveuser 318
			#設置執行不正常
319
			$result["status"]="false";
226 liveuser 320
 
3 liveuser 321
			#回傳結果
322
			return $result;
226 liveuser 323
 
324
			}#if end
325
 
3 liveuser 326
		#匯入 phpodt 套件
327
		include($phpOdsLibPath);
226 liveuser 328
 
3 liveuser 329
		#設置執行正常
226 liveuser 330
		$result["status"]="true";
331
 
3 liveuser 332
		#回傳結果
333
		return $result;
226 liveuser 334
 
335
		}#function importOdsLib end
336
 
3 liveuser 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(){
226 liveuser 353
 
3 liveuser 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 失敗
226 liveuser 369
		if($importOdsLib["status"]=="false"){
370
 
3 liveuser 371
			#設置錯誤訊息
372
			$result["error"]=$importLib;
226 liveuser 373
 
3 liveuser 374
			#設置執行不正常
375
			$result["status"]="false";
226 liveuser 376
 
3 liveuser 377
			#回傳結果
226 liveuser 378
			return $result;
379
 
3 liveuser 380
			}#if end
226 liveuser 381
 
3 liveuser 382
		#create a new ods file
226 liveuser 383
		$object=\newOds();
384
 
3 liveuser 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');
226 liveuser 387
 
3 liveuser 388
		#add a cell to sheet 0, row 0, cell 1, with value 1 and type float
226 liveuser 389
		$object->addCell(0,0,1,2,'float');
390
 
3 liveuser 391
		#add a cell to sheet 0, row 1, cell 0, with value 1 and type float
226 liveuser 392
		$object->addCell(0,1,0,1,'float');
393
 
3 liveuser 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');
226 liveuser 396
 
3 liveuser 397
		#save the object to a ods file
226 liveuser 398
		saveOds($object,'odT/demoOdf.ods');
399
 
3 liveuser 400
		#取得檔案路徑
401
		$result["content"]="odT/demoOdf.ods";
226 liveuser 402
 
3 liveuser 403
		#設置執行正常
404
		$result["status"]="true";
226 liveuser 405
 
3 liveuser 406
		#回傳結果
407
		return $result;
226 liveuser 408
 
3 liveuser 409
		}#function demoOds end
226 liveuser 410
 
3 liveuser 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){
226 liveuser 432
 
3 liveuser 433
		#初始化要回傳的結果
434
		$result=array();
226 liveuser 435
 
3 liveuser 436
		#取得當前執行的函數
437
		$result["function"]=__FUNCTION__;
438
 
439
		#如果 $conf 不為陣列
440
		if(gettype($conf)!="array"){
226 liveuser 441
 
3 liveuser 442
			#設置執行失敗
443
			$result["status"]="false";
226 liveuser 444
 
3 liveuser 445
			#設置執行錯誤訊息
446
			$result["error"][]="\$conf變數須為陣列形態";
447
 
448
			#如果傳入的參數為 null
449
			if($conf==null){
226 liveuser 450
 
3 liveuser 451
				#設置執行錯誤訊息
452
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 453
 
3 liveuser 454
				}#if end
455
 
456
			#回傳結果
457
			return $result;
226 liveuser 458
 
3 liveuser 459
			}#if end
226 liveuser 460
 
3 liveuser 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");
226 liveuser 479
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 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");
226 liveuser 488
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 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"){
226 liveuser 501
 
3 liveuser 502
			#設置錯誤狀態
503
			$result["status"]="false";
226 liveuser 504
 
3 liveuser 505
			#設置錯誤提示
506
			$result["error"]=$checkResult;
226 liveuser 507
 
3 liveuser 508
			#回傳結果
509
			return $result;
226 liveuser 510
 
3 liveuser 511
			}#if end
512
 
513
		#如果檢查不通過
514
		if($checkResult["passed"]=="false"){
226 liveuser 515
 
3 liveuser 516
			#設置錯誤狀態
517
			$result["status"]="false";
226 liveuser 518
 
3 liveuser 519
			#設置錯誤提示
520
			$result["error"]=$checkResult;
226 liveuser 521
 
3 liveuser 522
			#回傳結果
523
			return $result;
226 liveuser 524
 
3 liveuser 525
			}#if end
226 liveuser 526
 
3 liveuser 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();
226 liveuser 540
 
3 liveuser 541
		#create a new ods file
226 liveuser 542
		$object=\newOds();
543
 
3 liveuser 544
		#針對每個分頁
545
		foreach($conf["content"] as $tabName=>$tabContent){
226 liveuser 546
 
3 liveuser 547
			#如果 $tabContent 不為陣列或元素數量為0
548
			if(gettype($tabContent)!="array" || count($tabContent)==0){
226 liveuser 549
 
3 liveuser 550
				#結束foreach end
551
				break;
226 liveuser 552
 
3 liveuser 553
				}#if end
226 liveuser 554
 
3 liveuser 555
			#針對每個列
556
			foreach($tabContent as $rowName=>$rowContent){
226 liveuser 557
 
3 liveuser 558
				#如果 $rowContent 不為陣列或元素數量為0
559
				if(gettype($rowContent)!="array" || count($rowContent)==0){
226 liveuser 560
 
3 liveuser 561
					#結束foreach end
562
					break;
226 liveuser 563
 
3 liveuser 564
					}#if end
226 liveuser 565
 
3 liveuser 566
				#針對每個行
567
				foreach($rowContent as $colName=>$colContent){
226 liveuser 568
 
3 liveuser 569
					#如果 $colContent 不為陣列或元素數量為0
570
					if(gettype($colContent)!="array" || count($colContent)==0){
226 liveuser 571
 
3 liveuser 572
						#結束foreach end
573
						break;
226 liveuser 574
 
3 liveuser 575
						}#if end
226 liveuser 576
 
3 liveuser 577
					#針對每個欄位的內容
578
					for($i=0;$i<2;$i++){
226 liveuser 579
 
3 liveuser 580
						#如果內容元素不存在
581
						if(!isset($colContent[$i])){
226 liveuser 582
 
3 liveuser 583
							#如果是數值
584
							if($i==0){
226 liveuser 585
 
3 liveuser 586
								#設為空字串
587
								$colContent[$i]="";
226 liveuser 588
 
3 liveuser 589
								}#if end
226 liveuser 590
 
3 liveuser 591
							#反之如果是形態
592
							else if($i==1){
226 liveuser 593
 
3 liveuser 594
								#設為字串
595
								$colContent[$i]="string";
226 liveuser 596
 
3 liveuser 597
								}#if end
226 liveuser 598
 
3 liveuser 599
							}#if end
226 liveuser 600
 
3 liveuser 601
						}#for end
226 liveuser 602
 
3 liveuser 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]);
226 liveuser 605
 
3 liveuser 606
					}#foreach end
226 liveuser 607
 
3 liveuser 608
				}#foreache end
226 liveuser 609
 
3 liveuser 610
			}#foreach end
226 liveuser 611
 
3 liveuser 612
		#確保路徑
613
		#涵式說明:
614
		#確保路徑存在.
615
		#回傳的結果:
616
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
617
		#$result["error"],錯誤訊息陣列.
618
		#$resutl["function"],當前執行的涵式名稱.
619
		#必填的參數:
620
		#$conf["path"],要檢查的路徑
226 liveuser 621
		$conf["fileAccess::validatePath"]["path"]=$conf["filePathAndName"];
3 liveuser 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"]);
226 liveuser 631
 
3 liveuser 632
		#如果確保路徑失敗
633
		if($validatePath["status"]=="false"){
226 liveuser 634
 
3 liveuser 635
			#設置錯誤狀態
636
			$result["status"]="false";
226 liveuser 637
 
3 liveuser 638
			#設置錯誤提示
639
			$result["error"]=$validatePath;
226 liveuser 640
 
3 liveuser 641
			#回傳結果
642
			return $result;
226 liveuser 643
 
3 liveuser 644
			}#if end
226 liveuser 645
 
3 liveuser 646
		#save the object to a ods file
226 liveuser 647
		saveOds($object,$conf["filePathAndName"].".ods");
648
 
3 liveuser 649
		#取得ods檔案的路徑
650
		$result["content"]=$conf["filePathAndName"].".ods";
226 liveuser 651
 
3 liveuser 652
		#設置執行正常
653
		$result["status"]="true";
226 liveuser 654
 
3 liveuser 655
		#回傳結果
656
		return $result;
226 liveuser 657
 
3 liveuser 658
		}#function createOds end
226 liveuser 659
 
3 liveuser 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){
226 liveuser 681
 
3 liveuser 682
		#初始化要回傳的結果
683
		$result=array();
684
 
685
		#取得當前執行的函數名稱
686
		$result["function"]=__FUNCTION__;
687
 
688
		#如果沒有參數
689
		if(func_num_args()==0){
226 liveuser 690
 
3 liveuser 691
			#設置執行失敗
692
			$result["status"]="false";
226 liveuser 693
 
3 liveuser 694
			#設置執行錯誤訊息
695
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 696
 
3 liveuser 697
			#回傳結果
698
			return $result;
226 liveuser 699
 
3 liveuser 700
			}#if end
226 liveuser 701
 
3 liveuser 702
		#取得參數
703
		$result["argu"]=$conf;
704
 
705
		#如果 $conf 不為陣列
706
		if(gettype($conf)!="array"){
226 liveuser 707
 
3 liveuser 708
			#設置執行失敗
709
			$result["status"]="false";
226 liveuser 710
 
3 liveuser 711
			#設置執行錯誤訊息
712
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 713
 
3 liveuser 714
			#如果傳入的參數為 null
715
			if($conf==null){
226 liveuser 716
 
3 liveuser 717
				#設置執行錯誤訊息
718
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 719
 
3 liveuser 720
				}#if end
721
 
722
			#回傳結果
723
			return $result;
226 liveuser 724
 
3 liveuser 725
			}#if end
226 liveuser 726
 
3 liveuser 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");
226 liveuser 761
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 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"]);
226 liveuser 771
 
3 liveuser 772
		#如果檢查參數失敗
773
		if($checkArguments["status"]=="false"){
226 liveuser 774
 
3 liveuser 775
			#設置執行失敗
776
			$result["status"]="false";
226 liveuser 777
 
3 liveuser 778
			#設置執行錯誤訊息
779
			$result["error"]=$checkArguments;
226 liveuser 780
 
3 liveuser 781
			#回傳結果
782
			return $result;
226 liveuser 783
 
3 liveuser 784
			}#if end
226 liveuser 785
 
3 liveuser 786
		#如果檢查參數不通過
787
		if($checkArguments["passed"]=="false"){
226 liveuser 788
 
3 liveuser 789
			#設置執行失敗
790
			$result["status"]="false";
226 liveuser 791
 
3 liveuser 792
			#設置執行錯誤訊息
793
			$result["error"]=$checkArguments;
226 liveuser 794
 
3 liveuser 795
			#回傳結果
796
			return $result;
226 liveuser 797
 
798
			}#if end
799
 
3 liveuser 800
		#函式說明:
801
		#匯入phpodt函式庫的函式
802
		#回傳結果:
803
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
804
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
805
		#$result["function"],當前執行的函式名稱.
806
		#必填參數:
807
		#無
808
		#可省略參數:
809
		#無
810
		$importLib=od::importOdtLib();
226 liveuser 811
 
3 liveuser 812
		#如果匯入 phpodt 函式庫失敗
813
		if($importLib["status"]=="false"){
226 liveuser 814
 
3 liveuser 815
			#設置錯誤訊息
816
			$result["error"]=$importLib;
226 liveuser 817
 
3 liveuser 818
			#設置執行不正常
819
			$result["status"]="false";
226 liveuser 820
 
3 liveuser 821
			#回傳結果
822
			return $result;
226 liveuser 823
 
3 liveuser 824
			}#if end
226 liveuser 825
 
3 liveuser 826
		#建立實體
827
		$odt=\ODT::getInstance();
226 liveuser 828
 
3 liveuser 829
		#針對 $conf["content"] 的每個元素
830
		foreach($conf["content"] as $pKey=>$pVal){
226 liveuser 831
 
3 liveuser 832
			#新增段落
833
			$pKey=new \Paragraph();
226 liveuser 834
 
3 liveuser 835
			#設置內容
836
			$pKey->addText($pVal);
226 liveuser 837
 
3 liveuser 838
			}#foreach end
226 liveuser 839
 
3 liveuser 840
		#輸出置檔案
841
		$odt->output($conf["filePathAndName"].".odt");
226 liveuser 842
 
3 liveuser 843
		#取得檔案位置
844
		$result["content"]=$conf["filePathAndName"].".odt";
226 liveuser 845
 
3 liveuser 846
		#設置執行正常
847
		$result["status"]="true";
226 liveuser 848
 
3 liveuser 849
		#回傳結果
850
		return $result;
226 liveuser 851
 
3 liveuser 852
		}#function createOdt end
226 liveuser 853
 
3 liveuser 854
	}#class od end
226 liveuser 855
 
3 liveuser 856
?>