File: PHPReportCol.php

package info (click to toggle)
phpreports 0.4.9-2.1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 684 kB
  • ctags: 1,426
  • sloc: php: 3,377; xml: 203; makefile: 29; sql: 18; sh: 17; python: 10
file content (506 lines) | stat: -rwxr-xr-x 13,026 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
<?php
	/**
		Report column object
		It can be of three types: 
		1) REGULAR		   - where the element value is interpreted as pure text
		2) EXPRESSION	   - the element value will be evaluated with the eval() function
		3) RAW_EXPRESSION - the element value will be evaluated the same way as EXPRESSION, 
		                    but the htmlspecialchars function will be used on the result.
		4) FIELD			   - the column will try to retrieve a field value where the name 
		                    matches the element value (its CASE-SENSITIVE!)
	*/
	class PHPReportCol extends PHPReportXMLElement {
		var $_aParms;				// column parameters
		var $_sType;				// column type
		var $_sExpr;				// column expression
		var $_sNform;				// number format
		var $_iNformX;				// number format extended
		var $_bSuppr;				// suppress old values
		var $_oGroup;				// col group
		var $_sDecSep;				// decimal separator
		var $_sThoSep;				// thousand separator
		var $_oCurVal;				// current value
		var $_oOldVal;				// old column value
		var $_sEvenClass;			// class for use in even rows
		var $_sOddClass;			// class for use in odd rows
		var $_oLink;				// link element
		var $_oBookmark;			// bookmark element
		var $_oImg;					// image element
		var $_aTrans;				// translation array
		var $_sCellClassExpr;	// cell class expression
		var $_sOnClick;
		var $_sOnMouseOver;
		var $_sOnMouseOut;
		var $_oError;

		/**
			Constructor
		*/
		function PHPReportCol() {
			$this->_aParms			= Array();	
			$this->_sType			= "UNDEFINED";
			$this->_sExpr			= null;
			$this->_oGroup			= null;
			$this->_sNform			= null;
			$this->_iNformX		= -1;
			$this->_sDecSep		= ",";
			$this->_sThoSep		= ".";
			$this->_bSuppr			= false;
			$this->_oCurVal		= null; 
			$this->_oOldVal		= null;
			$this->_sEvenClass	= null;
			$this->_sOddClass		= null;
			$this->_oLink			= null;
			$this->_oBookmark		= null;
			$this->_oImg			= null;
			$this->_sClassExpr	= null;
			$this->_sOnClick		= "";
			$this->_sOnMouseOver	= "";
			$this->_sOnMouseOut	= "";
			$this->_oError			= new PHPReportsErrorTr();
			$this->makeTranslationArray();
		}

		function makeTranslationArray(){
			$this->_aTrans["TYPE"]				="TP";
			$this->_aTrans["NUMBERFORMAT"]	="NF";
			$this->_aTrans["NUMBERFORMATEX"]	="NE";
			$this->_aTrans["CELLCLASS"]		="CC";
			$this->_aTrans["TEXTCLASS"]		="TC";
			$this->_aTrans["ROWSPAN"]			="RS";
			$this->_aTrans["COLSPAN"]			="CS";
			$this->_aTrans["WIDTH"]				="WI";
			$this->_aTrans["HEIGHT"]			="HE";
			$this->_aTrans["ALIGN"]				="AL";
			$this->_aTrans["VALIGN"]			="VA";
			$this->_aTrans["ONCLICK"]			="OC";
			$this->_aTrans["ONMOUSEOVER"]		="MO";
			$this->_aTrans["ONMOUSEOUT"]		="MT";
		}

		/**
			Add a parameter
			@param PHPReportColParm - parameter object
		*/	
		function addParm($aParm_=null) {
			if($aParm_->getName()=="VISIBLE")
				return;
			if(is_null($this->_aTrans[$aParm_->getName()])) 
				$this->_oError->showMsg("NOXMLTRANS",array($aParm_->getName()));
			$this->_aParms[$this->_aTrans[$aParm_->getName()]]=$aParm_;
		}

		/**
			Gets a parameter value
			@param String parameter name
			@return Object parameter value
		*/
		function getParm($sParm_=null) {
			$oObj=$this->_aParms[$sParm_];
			if(is_null($oObj))
				return null;
			return $oObj->getValue();
		}

		/*
			Returns the parameters array - we dont need a method to set it,
			it MUST be set using the addParm to add the parameters one by one.
			@return Object[] parameters
		*/
		function getParms() {
			return $this->$_aParms;
		}

		/*
			Returns the XML open tag
			@param int row - row number to check about odd and even styles
			@return String XML open tag
		*/
		function getXMLOpen($iRow_=0) {
			$sStr		= "<C ";
			
			// check for even and odd cell classes
			if(!is_null($this->_sEvenClass)&&$iRow_%2==0) 
				$sStr .="CC=\"".$this->_sEvenClass."\" ";
			else if(!is_null($this->_sOddClass)&&$iRow_%2>0) 
				$sStr .="CC=\"".$this->_sOddClass."\" ";

			// check for expression on the CELLCLASS parameter
			if(!is_null($this->_sCellClassExpr))
				$sStr .= "CC=\"".eval($this->_sCellClassExpr)."\" ";
			
			// check if the CELLCLASS was processed
			$bClassProcessed = strpos($sStr,"CC")>0;	
			
			// loop on the parameters array
			$aKeys=array_keys($this->_aParms);
			$iSize=sizeof($aKeys);
			for($i=0;$i<$iSize;$i++) {
				$oParm=$this->_aParms[$aKeys[$i]];	// get the parameter object
				$sName=$aKeys[$i];						// get the parameter name
				$oVal =$oParm->getValue();				// and the parameter value
				
				// if its the CELLCLASS parm, check if it
				// it was not processed above
				if($sName!="CC" || ($sName=="CC" && !$bClassProcessed)) {	
					$sParm="$sName=\"$oVal\"";
					$sStr.=$sParm.($i==($iSize-1)?"":" ");
				}	
			}
			$sStr =trim($sStr).">";						// if you mind about processing, trim is
			return $sStr;									// here just to beautify stuff, you can remove it
		}

		/**
			Returns the XML close tag
			@return String XML closing tag
		*/
		function getXMLClose() {
			return "</C>";
		}

		/**
			Sets the column type
			@param String type
		*/
		function setType($sType_="REGULAR") {
			$this->_sType=$sType_;
		}

		/**
			Returns the column type
			@return String type
		*/
		function getType() {
			return $this->_sType;
		}

		/**
			Sets the column expression
			@param Object expression
		*/
		function setExpr($sExpr_=null) {
			$this->_sExpr=$sExpr_;
		}

		/**
			Gets the column value
			This function will be always called from a PHPReportRow, that 
			must provide the row number for checking if we must use an odd or even
			class (if its configured that way)
			@param int row number 
			@return Object value
		*/
		function getColValue($iRow_=0) {
			// if it's a command, run and return an empty string
			if($this->_sType=="CMD"){ 
				$this->availExpr($this->_sExpr);
				return "";
			}
			$sBookmark		= "";
			$sLinkOpen		= "";
			$sLinkClose		= "";
			$sImg				= "";
			$oBm				= $this->_oBookmark;
			$oLink			= $this->_oLink;
			$oImg				= $this->_oImg;

			// check if there is some bookmark
			if(!is_null($oBm)) 
				$sBookmark = "<BK HREF=\"".$this->getNextBookmark()."\" CC=\"".$oBm->getCellClass()."\" TC=\"".$oBm->getTextClass()."\">".$oBm->getBookmarkValue($this)."</BK>";
			
			// check if there is some link
			if(!is_null($oLink)) {
				$sLinkOpen = "<LI TITLE=\"".$oLink->getTitle()."\" TARGET=\"".$oLink->getTarget()."\" HREF=\"".$oLink->getLinkValue($this)."\">";
				$sLinkClose= "</LI>";
			}

			// check if there is some image
			if(!is_null($oImg)){
				$iWidth	= $oImg->getWidth();
				$iHeight = $oImg->getHeight();
				$iBorder = $oImg->getBorder();
				$sAlt		= $oImg->getAlt();
				$sImg = "<IMG ".($iWidth>0?" WIDTH=\"$iWidth\"":"").($iHeight>0?" HEIGHT=\"$iHeight\"":"").($iBorder>0?" BORDER=\"$iBorder\"":"").(!empty($sAlt)?" ALT=\"$sAlt\"":"").">".$oImg->getURL()."</IMG>";
			}
			
			// column value	
			$this->avail();
			return $this->getXMLOpen($iRow_).$sBookmark.$sLinkOpen.$sImg.($this->isSuppressed()&&strcmp($this->_oCurVal,$this->_oOldVal)==0?"&#160;":$this->_oCurVal).$sLinkClose.$this->getXMLClose();
		}

		/**
			Returns the last value processed on this column
			@return Object value
		*/
		function getOldValue() {
			return $this->_oOldVal;
		}

		function resetOldValue() {
			$this->_oOldVal=null;
			$this->resetCurValue();
		}

		function resetCurValue() {
			$this->_oCurVal=null;
		}
		
		/**
			Returns the column expression
			@return String expression
		*/		
		function getExpr() {
			return $this->_sExpr;
		}

		/**
			Returns the column evaluated value
			@return Object value
		*/
		function avail() {
			// stores the old value
			$this->_oOldVal=$this->_oCurVal;
			
			// get the column value here
			$this->_oCurVal = $this->availValue($this->_sExpr);
				
			// if its not null and have some special stuff on it 	
			if(!is_null($this->_oCurVal)) {
				// number format exists
				if(!is_null($this->_sNform)){	
					// needs to be a string or a numeric value to apply the formatting 
					if(strpos($this->_sNform,"%s") || is_numeric($this->_oCurVal))
						$this->_oCurVal = sprintf($this->_sNform,$this->_oCurVal);
				}
				// number format extended
				if($this->_iNformX>=0 && is_numeric($this->_oCurVal))
					$this->_oCurVal = number_format($this->_oCurVal,$this->_iNformX,$this->_sDecSep,$this->_sThoSep);	
			}
			return $this->_oCurVal;
		}

		/**
			Return the column value
			@param String value
		*/
		function availValue($sExpr_=null){
			if(is_null($sExpr_))
				return $sExpr_;

			if($this->_sType=="EXPRESSION") 
				return htmlspecialchars($this->availExpr($sExpr_),ENT_NOQUOTES);
			else if($this->_sType=="RAW_EXPRESSION") 
				return $this->availExpr($sExpr_);
			else if($this->_sType=="FIELD")
				return htmlspecialchars($this->getValue($sExpr_),ENT_NOQUOTES);
			else 
				return $sExpr_;					
		}
		
		/**
			Evaluate the column, if it's the EXPRESSION type
			@param String expression
		*/
		function availExpr($sExpr_=null){
			if(is_null($sExpr_))
				return $sExpr_;
			return eval($sExpr_);	
		}
		
		/**
			Returns a field value inside the column group
			@param String field
		*/
		function getValue($sField_) {
			return $this->_oGroup->getValue($sField_);
		}

		/**
			Returns the sum of a field inside the column group
			@param String field
		*/		
		function getSum($sField_) {
			return $this->_oGroup->getSum($sField_);
		}
		
		/**
			Returns the max value of a field inside the column group
			@param String field
		*/		
		function getMax($sField_) {
			return $this->_oGroup->getMax($sField_);
		}
		
		/**
			Returns the min value of a field inside the column group
			@param String field
		*/		
		function getMin($sField_) {
			return $this->_oGroup->getMin($sField_);
		}

		function getAvg($sField_) {
			return $this->_oGroup->getAvg($sField_);
		}

		function getRowCount() {
			return $this->_oGroup->getRowCount();
		}

		function getRowNum() {
			$oPage =& $this->_oGroup->getPage();
			return $oPage->getRowNum();
		}
		
		function getPageNum() {
			$oPage =& $this->_oGroup->getPage();
			return $oPage->getPageNum();
		}
		
		function setPageNum($iNum_=0) {
			$oPage =& $this->_oGroup->getPage();
			return $oPage->setPageNum($iNum_);
		}

		function resetPageNum(){
			return $this->setPageNum(0);
		}
		
		/**
			Sets the column group
			@param Object group
		*/
		function setGroup(&$oGroup_) {
			$this->_oGroup=&$oGroup_;
			$oRpt=$oGroup_->getReport();
			if(!is_null($oRpt)) {
				$this->_sDecSep=$oRpt->getDecSep();
				$this->_sThoSep=$oRpt->getThoSep();
			}
		}

		/**
			Set the number format
			@param String format (printf like)
		*/
		function setNumberFormat($sFormat_=null) {
			$this->_sNform=$sFormat_;
		}

		/**
			Return the number format
			@return String format
		*/
		function getNumberFormat() {
			return $this->_sNform;
		}
		
		/**
			Set the number format decimal places
			@param int - number of decimal places
		*/
		function setNumberFormatEx($iNum_=0) {
			$this->_iNformX=$iNum_;
		}

		/**
			Return the number of decimal places
			@return int - number of decimal places
		*/
		function getNumberFormatEx() {
			return $this->_iNformX;
		}

		/**
			Set if the column will print blank values
			when the current value is the same of the
			last printed value
			@param String YES,NO,TRUE,FALSE
		*/
		function suppress($sStr_="FALSE") {
			$sStr = strtoupper($sStr_);
			// don't use strpos here, there's some bug there to check this ...
			if($sStr=="TRUE"||$sStr=="YES")
				$this->_bSuppr=true;
		}

		/**
			Return if its a suppressed values column
			@return boolean 
		*/
		function isSuppressed() {
			return $this->_bSuppr;
		}

		/**
			Set the even row class this column will fit on
			@param String class
		*/
		function setEvenClass($sClass_=null) {
			$this->_sEvenClass=$sClass_;
		}
		
		/**
			Set the odd row class this column will fit on
			@param String class
		*/
		function setOddClass($sClass_=null) {
			$this->_sOddClass=$sClass_;
		}

		function setCellClassExpr($sExpr_=null){
			$this->_sCellClassExpr=$sExpr_;
		}

		/**
			Add a link object in this column 
			@param PHPReportLink link
		*/			
		function addLink($oLink_) {
			$this->_oLink=$oLink_;
		}
		
		/**
			Add a bookmark object in this column 
			@param PHPReportBookmark link
		*/			
		function addBookmark($oBm_) {
			$this->_oBookmark=$oBm_;
		}

		function addImg($oImg_){
			$this->_oImg=$oImg_;
		}

		function getNextBookmark() {
			$oRpt=&$this->_oGroup->getReport();
			return $oRpt->getNextBookmark();
		}

		function getParameter($oKey_) {
			return $this->_oGroup->getParameter($oKey_);
		}

		function getFileName(){
			$oPage =& $this->_oGroup->getPage();
			return basename($oPage->getFileName());
		}

		function getEnvObj($sKey_){
			return $this->_oGroup->getEnvObj($sKey_);
		}

		function setOnClick($sEvent_){
			$this->_sOnClick=$sEvent_;
		}

		function setOnMouseOver($sEvent_){
			$this->_sOnMouseOver=$sEvent_;
		}

		function setOnMouseOut($sEvent_){
			$this->_sOnMouseOut=$sEvent_;
		}
	}
?>