PageRenderTime 56ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/includes/php/PHPReports/php/PHPReportCol.php

http://tracmor.googlecode.com/
PHP | 506 lines | 290 code | 60 blank | 156 comment | 31 complexity | ed1ffee3655a174bc45abdfc4f8dab61 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. /**
  3. Report column object
  4. It can be of three types:
  5. 1) REGULAR - where the element value is interpreted as pure text
  6. 2) EXPRESSION - the element value will be evaluated with the eval() function
  7. 3) RAW_EXPRESSION - the element value will be evaluated the same way as EXPRESSION,
  8. but the htmlspecialchars function will be used on the result.
  9. 4) FIELD - the column will try to retrieve a field value where the name
  10. matches the element value (its CASE-SENSITIVE!)
  11. */
  12. class PHPReportCol extends PHPReportXMLElement {
  13. var $_aParms; // column parameters
  14. var $_sType; // column type
  15. var $_sExpr; // column expression
  16. var $_sNform; // number format
  17. var $_iNformX; // number format extended
  18. var $_bSuppr; // suppress old values
  19. var $_oGroup; // col group
  20. var $_sDecSep; // decimal separator
  21. var $_sThoSep; // thousand separator
  22. var $_oCurVal; // current value
  23. var $_oOldVal; // old column value
  24. var $_sEvenClass; // class for use in even rows
  25. var $_sOddClass; // class for use in odd rows
  26. var $_oLink; // link element
  27. var $_oBookmark; // bookmark element
  28. var $_oImg; // image element
  29. var $_aTrans; // translation array
  30. var $_sCellClassExpr; // cell class expression
  31. var $_sOnClick;
  32. var $_sOnMouseOver;
  33. var $_sOnMouseOut;
  34. var $_oError;
  35. /**
  36. Constructor
  37. */
  38. function PHPReportCol() {
  39. $this->_aParms = Array();
  40. $this->_sType = "UNDEFINED";
  41. $this->_sExpr = null;
  42. $this->_oGroup = null;
  43. $this->_sNform = null;
  44. $this->_iNformX = -1;
  45. $this->_sDecSep = ",";
  46. $this->_sThoSep = ".";
  47. $this->_bSuppr = false;
  48. $this->_oCurVal = null;
  49. $this->_oOldVal = null;
  50. $this->_sEvenClass = null;
  51. $this->_sOddClass = null;
  52. $this->_oLink = null;
  53. $this->_oBookmark = null;
  54. $this->_oImg = null;
  55. $this->_sClassExpr = null;
  56. $this->_sOnClick = "";
  57. $this->_sOnMouseOver = "";
  58. $this->_sOnMouseOut = "";
  59. $this->_oError = new PHPReportsErrorTr();
  60. $this->makeTranslationArray();
  61. }
  62. function makeTranslationArray(){
  63. $this->_aTrans["TYPE"] ="TP";
  64. $this->_aTrans["NUMBERFORMAT"] ="NF";
  65. $this->_aTrans["NUMBERFORMATEX"] ="NE";
  66. $this->_aTrans["CELLCLASS"] ="CC";
  67. $this->_aTrans["TEXTCLASS"] ="TC";
  68. $this->_aTrans["ROWSPAN"] ="RS";
  69. $this->_aTrans["COLSPAN"] ="CS";
  70. $this->_aTrans["WIDTH"] ="WI";
  71. $this->_aTrans["HEIGHT"] ="HE";
  72. $this->_aTrans["ALIGN"] ="AL";
  73. $this->_aTrans["VALIGN"] ="VA";
  74. $this->_aTrans["ONCLICK"] ="OC";
  75. $this->_aTrans["ONMOUSEOVER"] ="MO";
  76. $this->_aTrans["ONMOUSEOUT"] ="MT";
  77. }
  78. /**
  79. Add a parameter
  80. @param PHPReportColParm - parameter object
  81. */
  82. function addParm($aParm_=null) {
  83. if($aParm_->getName()=="VISIBLE")
  84. return;
  85. if(is_null($this->_aTrans[$aParm_->getName()]))
  86. $this->_oError->showMsg("NOXMLTRANS",array($aParm_->getName()));
  87. $this->_aParms[$this->_aTrans[$aParm_->getName()]]=$aParm_;
  88. }
  89. /**
  90. Gets a parameter value
  91. @param String parameter name
  92. @return Object parameter value
  93. */
  94. function getParm($sParm_=null) {
  95. $oObj=$this->_aParms[$sParm_];
  96. if(is_null($oObj))
  97. return null;
  98. return $oObj->getValue();
  99. }
  100. /*
  101. Returns the parameters array - we dont need a method to set it,
  102. it MUST be set using the addParm to add the parameters one by one.
  103. @return Object[] parameters
  104. */
  105. function getParms() {
  106. return $this->$_aParms;
  107. }
  108. /*
  109. Returns the XML open tag
  110. @param int row - row number to check about odd and even styles
  111. @return String XML open tag
  112. */
  113. function getXMLOpen($iRow_=0) {
  114. $sStr = "<C ";
  115. // check for even and odd cell classes
  116. if(!is_null($this->_sEvenClass)&&$iRow_%2==0)
  117. $sStr .="CC=\"".$this->_sEvenClass."\" ";
  118. else if(!is_null($this->_sOddClass)&&$iRow_%2>0)
  119. $sStr .="CC=\"".$this->_sOddClass."\" ";
  120. // check for expression on the CELLCLASS parameter
  121. if(!is_null($this->_sCellClassExpr))
  122. $sStr .= "CC=\"".eval($this->_sCellClassExpr)."\" ";
  123. // check if the CELLCLASS was processed
  124. $bClassProcessed = strpos($sStr,"CC")>0;
  125. // loop on the parameters array
  126. $aKeys=array_keys($this->_aParms);
  127. $iSize=sizeof($aKeys);
  128. for($i=0;$i<$iSize;$i++) {
  129. $oParm=$this->_aParms[$aKeys[$i]]; // get the parameter object
  130. $sName=$aKeys[$i]; // get the parameter name
  131. $oVal =$oParm->getValue(); // and the parameter value
  132. // if its the CELLCLASS parm, check if it
  133. // it was not processed above
  134. if($sName!="CC" || ($sName=="CC" && !$bClassProcessed)) {
  135. $sParm="$sName=\"$oVal\"";
  136. $sStr.=$sParm.($i==($iSize-1)?"":" ");
  137. }
  138. }
  139. $sStr =trim($sStr).">"; // if you mind about processing, trim is
  140. return $sStr; // here just to beautify stuff, you can remove it
  141. }
  142. /**
  143. Returns the XML close tag
  144. @return String XML closing tag
  145. */
  146. function getXMLClose() {
  147. return "</C>";
  148. }
  149. /**
  150. Sets the column type
  151. @param String type
  152. */
  153. function setType($sType_="REGULAR") {
  154. $this->_sType=$sType_;
  155. }
  156. /**
  157. Returns the column type
  158. @return String type
  159. */
  160. function getType() {
  161. return $this->_sType;
  162. }
  163. /**
  164. Sets the column expression
  165. @param Object expression
  166. */
  167. function setExpr($sExpr_=null) {
  168. $this->_sExpr=$sExpr_;
  169. }
  170. /**
  171. Gets the column value
  172. This function will be always called from a PHPReportRow, that
  173. must provide the row number for checking if we must use an odd or even
  174. class (if its configured that way)
  175. @param int row number
  176. @return Object value
  177. */
  178. function getColValue($iRow_=0) {
  179. // if it's a command, run and return an empty string
  180. if($this->_sType=="CMD"){
  181. $this->availExpr($this->_sExpr);
  182. return "";
  183. }
  184. $sBookmark = "";
  185. $sLinkOpen = "";
  186. $sLinkClose = "";
  187. $sImg = "";
  188. $oBm = $this->_oBookmark;
  189. $oLink = $this->_oLink;
  190. $oImg = $this->_oImg;
  191. // check if there is some bookmark
  192. if(!is_null($oBm))
  193. $sBookmark = "<BK HREF=\"".$this->getNextBookmark()."\" CC=\"".$oBm->getCellClass()."\" TC=\"".$oBm->getTextClass()."\">".$oBm->getBookmarkValue($this)."</BK>";
  194. // check if there is some link
  195. if(!is_null($oLink)) {
  196. $sLinkOpen = "<LI TITLE=\"".$oLink->getTitle()."\" TARGET=\"".$oLink->getTarget()."\" HREF=\"".$oLink->getLinkValue($this)."\">";
  197. $sLinkClose= "</LI>";
  198. }
  199. // check if there is some image
  200. if(!is_null($oImg)){
  201. $iWidth = $oImg->getWidth();
  202. $iHeight = $oImg->getHeight();
  203. $iBorder = $oImg->getBorder();
  204. $sAlt = $oImg->getAlt();
  205. $sImg = "<IMG ".($iWidth>0?" WIDTH=\"$iWidth\"":"").($iHeight>0?" HEIGHT=\"$iHeight\"":"").($iBorder>0?" BORDER=\"$iBorder\"":"").(!empty($sAlt)?" ALT=\"$sAlt\"":"").">".$oImg->getURL()."</IMG>";
  206. }
  207. // column value
  208. $this->avail();
  209. return $this->getXMLOpen($iRow_).$sBookmark.$sLinkOpen.$sImg.($this->isSuppressed()&&strcmp($this->_oCurVal,$this->_oOldVal)==0?"&#160;":$this->_oCurVal).$sLinkClose.$this->getXMLClose();
  210. }
  211. /**
  212. Returns the last value processed on this column
  213. @return Object value
  214. */
  215. function getOldValue() {
  216. return $this->_oOldVal;
  217. }
  218. function resetOldValue() {
  219. $this->_oOldVal=null;
  220. $this->resetCurValue();
  221. }
  222. function resetCurValue() {
  223. $this->_oCurVal=null;
  224. }
  225. /**
  226. Returns the column expression
  227. @return String expression
  228. */
  229. function getExpr() {
  230. return $this->_sExpr;
  231. }
  232. /**
  233. Returns the column evaluated value
  234. @return Object value
  235. */
  236. function avail() {
  237. // stores the old value
  238. $this->_oOldVal=$this->_oCurVal;
  239. // get the column value here
  240. $this->_oCurVal = $this->availValue($this->_sExpr);
  241. // if its not null and have some special stuff on it
  242. if(!is_null($this->_oCurVal)) {
  243. // number format exists
  244. if(!is_null($this->_sNform)){
  245. // needs to be a string or a numeric value to apply the formatting
  246. if(strpos($this->_sNform,"%s") || is_numeric($this->_oCurVal))
  247. $this->_oCurVal = sprintf($this->_sNform,$this->_oCurVal);
  248. }
  249. // number format extended
  250. if($this->_iNformX>=0 && is_numeric($this->_oCurVal))
  251. $this->_oCurVal = number_format($this->_oCurVal,$this->_iNformX,$this->_sDecSep,$this->_sThoSep);
  252. }
  253. return $this->_oCurVal;
  254. }
  255. /**
  256. Return the column value
  257. @param String value
  258. */
  259. function availValue($sExpr_=null){
  260. if(is_null($sExpr_))
  261. return $sExpr_;
  262. if($this->_sType=="EXPRESSION")
  263. return htmlspecialchars($this->availExpr($sExpr_),ENT_NOQUOTES);
  264. else if($this->_sType=="RAW_EXPRESSION")
  265. return $this->availExpr($sExpr_);
  266. else if($this->_sType=="FIELD")
  267. return htmlspecialchars($this->getValue($sExpr_),ENT_NOQUOTES);
  268. else
  269. return $sExpr_;
  270. }
  271. /**
  272. Evaluate the column, if it's the EXPRESSION type
  273. @param String expression
  274. */
  275. function availExpr($sExpr_=null){
  276. if(is_null($sExpr_))
  277. return $sExpr_;
  278. return eval($sExpr_);
  279. }
  280. /**
  281. Returns a field value inside the column group
  282. @param String field
  283. */
  284. function getValue($sField_) {
  285. return $this->_oGroup->getValue($sField_);
  286. }
  287. /**
  288. Returns the sum of a field inside the column group
  289. @param String field
  290. */
  291. function getSum($sField_) {
  292. return $this->_oGroup->getSum($sField_);
  293. }
  294. /**
  295. Returns the max value of a field inside the column group
  296. @param String field
  297. */
  298. function getMax($sField_) {
  299. return $this->_oGroup->getMax($sField_);
  300. }
  301. /**
  302. Returns the min value of a field inside the column group
  303. @param String field
  304. */
  305. function getMin($sField_) {
  306. return $this->_oGroup->getMin($sField_);
  307. }
  308. function getAvg($sField_) {
  309. return $this->_oGroup->getAvg($sField_);
  310. }
  311. function getRowCount() {
  312. return $this->_oGroup->getRowCount();
  313. }
  314. function getRowNum() {
  315. $oPage =& $this->_oGroup->getPage();
  316. return $oPage->getRowNum();
  317. }
  318. function getPageNum() {
  319. $oPage =& $this->_oGroup->getPage();
  320. return $oPage->getPageNum();
  321. }
  322. function setPageNum($iNum_=0) {
  323. $oPage =& $this->_oGroup->getPage();
  324. return $oPage->setPageNum($iNum_);
  325. }
  326. function resetPageNum(){
  327. return $this->setPageNum(0);
  328. }
  329. /**
  330. Sets the column group
  331. @param Object group
  332. */
  333. function setGroup(&$oGroup_) {
  334. $this->_oGroup=&$oGroup_;
  335. $oRpt=$oGroup_->getReport();
  336. if(!is_null($oRpt)) {
  337. $this->_sDecSep=$oRpt->getDecSep();
  338. $this->_sThoSep=$oRpt->getThoSep();
  339. }
  340. }
  341. /**
  342. Set the number format
  343. @param String format (printf like)
  344. */
  345. function setNumberFormat($sFormat_=null) {
  346. $this->_sNform=$sFormat_;
  347. }
  348. /**
  349. Return the number format
  350. @return String format
  351. */
  352. function getNumberFormat() {
  353. return $this->_sNform;
  354. }
  355. /**
  356. Set the number format decimal places
  357. @param int - number of decimal places
  358. */
  359. function setNumberFormatEx($iNum_=0) {
  360. $this->_iNformX=$iNum_;
  361. }
  362. /**
  363. Return the number of decimal places
  364. @return int - number of decimal places
  365. */
  366. function getNumberFormatEx() {
  367. return $this->_iNformX;
  368. }
  369. /**
  370. Set if the column will print blank values
  371. when the current value is the same of the
  372. last printed value
  373. @param String YES,NO,TRUE,FALSE
  374. */
  375. function suppress($sStr_="FALSE") {
  376. $sStr = strtoupper($sStr_);
  377. // don't use strpos here, there's some bug there to check this ...
  378. if($sStr=="TRUE"||$sStr=="YES")
  379. $this->_bSuppr=true;
  380. }
  381. /**
  382. Return if its a suppressed values column
  383. @return boolean
  384. */
  385. function isSuppressed() {
  386. return $this->_bSuppr;
  387. }
  388. /**
  389. Set the even row class this column will fit on
  390. @param String class
  391. */
  392. function setEvenClass($sClass_=null) {
  393. $this->_sEvenClass=$sClass_;
  394. }
  395. /**
  396. Set the odd row class this column will fit on
  397. @param String class
  398. */
  399. function setOddClass($sClass_=null) {
  400. $this->_sOddClass=$sClass_;
  401. }
  402. function setCellClassExpr($sExpr_=null){
  403. $this->_sCellClassExpr=$sExpr_;
  404. }
  405. /**
  406. Add a link object in this column
  407. @param PHPReportLink link
  408. */
  409. function addLink($oLink_) {
  410. $this->_oLink=$oLink_;
  411. }
  412. /**
  413. Add a bookmark object in this column
  414. @param PHPReportBookmark link
  415. */
  416. function addBookmark($oBm_) {
  417. $this->_oBookmark=$oBm_;
  418. }
  419. function addImg($oImg_){
  420. $this->_oImg=$oImg_;
  421. }
  422. function getNextBookmark() {
  423. $oRpt=&$this->_oGroup->getReport();
  424. return $oRpt->getNextBookmark();
  425. }
  426. function getParameter($oKey_) {
  427. return $this->_oGroup->getParameter($oKey_);
  428. }
  429. function getFileName(){
  430. $oPage =& $this->_oGroup->getPage();
  431. return basename($oPage->getFileName());
  432. }
  433. function getEnvObj($sKey_){
  434. return $this->_oGroup->getEnvObj($sKey_);
  435. }
  436. function setOnClick($sEvent_){
  437. $this->_sOnClick=$sEvent_;
  438. }
  439. function setOnMouseOver($sEvent_){
  440. $this->_sOnMouseOver=$sEvent_;
  441. }
  442. function setOnMouseOut($sEvent_){
  443. $this->_sOnMouseOut=$sEvent_;
  444. }
  445. }
  446. ?>