- <?php
- /**
- * sptpl_clsRow.php
- *
- * @copyright sptpl_clsRow.php is part of Sptpl project {@link http://www.andrioli.com/en/sptpl.html} and it is LGPL
- * @author Andrioli Darvin <darvin (inside) andrioli (dot) com>
- * @version $Header: d:\cvs/classistd/sptpl/sptpl_clsRow.php,v 2.10 2005/03/02 21:00:54 Darvin Exp $
- */
- /*
- * +-------------------------------------------------------------------------+
- * | Sptpl |
- * +-------------------------------------------------------------------------+
- * | Copyright (c) 2003-2005 Andrioli Darvin |
- * | Email <darvin (inside) andrioli (dot) com> |
- * | Web http://www.andrioli.com/en/sptpl.html |
- * | Download http://www.phpclasses.org/browse.html/package/1326.html |
- * | |
- * +-------------------------------------------------------------------------+
- * | This library is free software; you can redistribute it and/or modify |
- * | it under the terms of the GNU Lesser General Public License as |
- * | published by the Free Software Foundation; either version 2 of the |
- * | License, or (at your option) any later version. |
- * | |
- * | This library is distributed in the hope that it will be useful, but |
- * | WITHOUT ANY WARRANTY; without even the implied warranty of |
- * | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
- * | Lesser General Public License for more details. |
- * | |
- * | You should have received a copy of the GNU Lesser General Public |
- * | License along with this library; if not, write to the Free Software |
- * | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
- * +-------------------------------------------------------------------------+
- */
-
-
-
- class CRow {
-
- /**
- * Text for this row ready to be evaled
- * @var string $RowText
- */
- var $RowText;
- /**
- * reference to the instance of DataManager, created by the class sptpl
- * @var object DataStorage $DataMgr
- */
- var $DataMgr;
- /**
- * Vertical position (optional). Specify the position for
- * the current row.
- * Values: top,bottom,relative,absolute,newpage
- * @var string $VPos
- * @see ParseXml()
- */
- var $VPos;
-
- /**
- * Row number, it specify the row namuber if the value for $VPos is 'absolute'
- * or 'relative'
- * @var integer $RowPos
- * @see $VPos
- */
- var $RowPos;
- /**
- * Orizontal alignment: right, center, left
- * Default: left
- * @var string $Align
- */
- var $Align;
- /**
- * Column where start the row. This value is added to the column calculated
- * by the parameter align
- * Default: 0
- * @var integer $ColPos
- */
- var $ColPos;
- /**
- * during row evaluation should I use the current value
- * or the oldest (i.e when close one group sometime I need
- * the values from the previous row
- * Values:
- * CURRENTVALUE: use the current value
- * OLDVALUE : use the previous value
- * Default: CURRENTVALUE
- * @var string $ValueType
- */
- var $ValueType;
- /**
- * Which font I should be used to print this row
- * Default: ''
- * @var string $FontId
- */
- var $FontId;
- /**
- * Which columnset should be used to print the current row
- * Default: NONE, no columnset required.
- * @var string
- */
- var $ColumnSet;
- /**
- * No. of column where put the text
- * Default: 0
- * @var integere
- */
- var $Column;
- /**
- * Class constructor
- * @parameter object DataStorage &$RefToDataMgr Reference to the istance of CDataManeger
- * made by the class sptpl.
- * @parameter object CXml2Array $Node definition node for the current istance
- * @parameter string $ValueType during row evaluation should I use the current value
- * or the oldest (i.e when close one group somethime I need
- * some value from the previous row
- * @access public
- */
- function CRow(&$RefToDataMgr,$Cfg=NULL,$ValueType=CURRENTVALUE)
- {
- $this->DataMgr=&$RefToDataMgr;
- if(!is_object($this->DataMgr))
- trigger_error('Internal error, CRow, first parameter should be an object', E_USER_ERROR);
- $this->VPos="";
- $this->RowPos=0;
- $this->Align='';
- $this->ColPos=0;
- $this->ValueType=$ValueType;
- $this->FontId='';
- $this->ColumnSet=NONE;
- $this->Column=0;
- if($Cfg!=NULL)
- $this->ParseXml($Cfg);
-
- }
-
-
- /**
- *
- * Parse the row tag and its childs to set the intenal structure
- *
- * @param object CXml2Array $Node
- * @access public
- */
- function ParseXml($Cfg)
- {
- // $Cfg->ArrayDump();
- // I Must reset the internal pointer. I already done a llop into the attributes
- $Cfg->EachAttribute(true);
- while(($ret=$Cfg->EachAttribute())!=FALSE)
- {
- // var_dump($ret);
- // echo "<br>";
- list($AttribName,$value)=$ret;
- switch(strtolower($AttribName))
- {
- case 'vpos' :
- $attr=strtolower($value);
- switch($attr) {
- case 'top' :
- case 'bottom' :
- case 'relative' :
- case 'absolute' :
- case 'newpage' :
- $this->VPos=$attr;
- break;
- default :
- trigger_error('Unespected value \''.$attr.'\' for the attribute vpos', E_USER_ERROR);
- break;
- }
- break;
- case 'rowpos' :
- $this->RowPos=$value;
- if(!is_numeric($this->RowPos))
- trigger_error('The attribute RowPos should be a number', E_USER_ERROR);
- break;
- case 'fontid' :
- $this->FontId=$value;
- break;
- case 'align' :
- $attr=strtolower($value);
- switch($attr) {
- case 'left' :
- case 'right' :
- case 'center' :
- $this->Align=$attr;
- break;
- default :
- trigger_error('Unespected value \''.$attr.'\' for the attribute align', E_USER_ERROR);
- break;
- }
- break;
- case 'colpos' :
- $this->ColPos=$value;
- if(!is_numeric($this->ColPos))
- trigger_error('The attribute ColPos should be a number', E_USER_ERROR);
- break;
- case 'columnset' :
- $this->ColumnSet=$value;
- break;
- case 'column' :
- $this->Column=$value;
- if(!is_numeric($this->Column))
- trigger_error('The attribute column should be a number', E_USER_ERROR);
- break;
- }
- }
- // var_dump(nl2br(GetDomValue($Node)));
- //var_dump($this);
- // echo "<hr><br>";
- $this->RowText=$this->_ParseRow($Cfg->GetText());
- // var_dump(nl2br($this->RowText));
- }
-
- /**
- * Parse the template row from the xml file and convert it into
- * internal format suitable to be eval'ed
- *
- * @param string Row
- * @access private
- */
- function _ParseRow($Row)
- {
- $outText="";
- $Offset=0;
- while(($StartPos=strpos($Row,'{',$Offset))!==FALSE)
- {
- $outText.="\"".substr($Row,$Offset,$StartPos-$Offset)."\"";
- // Where is the end
- if(($EndPos=strpos($Row,'}',$StartPos))===FALSE)
- trigger_error("Open { without the close }",E_USER_ERROR);
- $outText.=" . ".$this->_ExtractVar(substr($Row,$StartPos,$EndPos-$StartPos))." . ";
- $Offset=$EndPos+1;
- }
- // Last part of the text
- $outText.="\"".substr($Row,$Offset)."\"";
- return($outText);
- }
- /**
- * Parse the text and decode the function or the data field from the given text
- *
- * @param string Text
- * @access private
- */
- function _ExtractVar($Text)
- {
- $OutText="";
- if(preg_match("/^\{(\w+)\(([\.\$\w\][,\'\"-\/ ]+)*\)\}*/",$Text,$var))
- {
- // Function Type: $var[1] -> Function name
- // $var[2] -> parameters
- // Is this function defined inside the DataManager class?
- // If so, I prepend $this to the function's name
- $LocalFunction='';
- if(method_exists($this->DataMgr,$var[1]))
- {
- $LocalFunction='$this->';
- }
-
- $OutText.='$this->GetEvalValue("'.$var[1].'",'.$LocalFunction.$var[1]."(";
- if(array_key_exists(2,$var))
- {
- $param=explode(",",$var[2]);
- $i=0;
- foreach($param as $value)
- {
- if($i) { $OutText.=",";}
- $OutText.=$this->_ExtractVar($value);
- $i++;
- }
- }
- $OutText.="))";
- }
- else
- {
- if(preg_match('/^\{*\$([a-zA-Z0-9]+)((\[[0-9a-zA-Z\'\"_]+\])*)\}*/',$Text,$var)) //'"
- {
- // Variable Type: $var[1] -> Variable name
- // $var[2] -> squares bracket used by array
- $FuncGetVal=($this->ValueType==CURRENTVALUE)?'$this->Values':'$this->OldValues';
- $OutText.='$this->GetEvalValue("'.$var[1].'",'.$FuncGetVal.'["'.$var[1].'"]'.$var[2].')';
- }
- else
- $OutText=$Text;
- }
- return($OutText);
- }
-
- /**
- * Write the text for this row. Actualy this function call the DataStorage to eval
- * the text, then it pass tha evalued text to the PageManager to perform the real output
- * @parameter object CPageMgr &$PageMgr reference to PageManager
- * @access public
- */
- function WriteOut(&$PageMgr)
- {
- if(!is_object($PageMgr))
- trigger_error('Internal error, WriteOut, first parameter should be an object', E_USER_ERROR);
- $evaluated=$this->DataMgr->EvalText($this->RowText);
- // Should I setup a new column set ?
- if($this->ColumnSet!=NONE)
- $PageMgr->NewColumnSet($this->ColumnSet);
- // Check wheter I need to move the current line.
- switch($this->VPos) {
- case 'top' :
- $PageMgr->MvTop();
- break;
- case 'bottom' :
- $PageMgr->MvBottom();
- break;
- case 'absolute' :
- $PageMgr->MvAbsolutePos($this->RowPos);
- break;
- case 'relative' :
- if(!$PageMgr->MvRelativePos($this->RowPos))
- trigger_error('Error in relative move of current line by '.$this->RowPos.' rows',E_USER_ERROR);
- break;
- case 'newpage' :
- $PageMgr->NewPage();
- break;
- }
- // var_dump($this->RowText);
- $PageMgr->WriteOut($evaluated,$this->Align,$this->ColPos,$this->Column,$this->FontId);
- }
-
- /**
- * @access public
- */
- function GetEvaledText()
- {
- return($this->DataMgr->EvalText($this->RowText));
- }
-
- }
-
-
- /**
- * Particular CROw used as header line on the page
- */
- class CRowHeader extends CRow
- {
- function CRowHeader(&$RefToDataMgr,$Node=NULL,$ValueType=CURRENTVALUE)
- {
- parent::CRow($RefToDataMgr,$Node,$ValueType);
- }
-
- function WriteOut(&$PageMgr)
- {
- if(!is_object($PageMgr))
- trigger_error('Internal error, WriteOut, first parameter should be an object', E_USER_ERROR);
- $evaluated=$this->DataMgr->EvalText($this->RowText);
- // var_dump($this->RowText);
- $PageMgr->WriteOutHeaderRow($evaluated,$this->Align,$this->ColPos,$this->FontId);
- }
-
- }
-
- /**
- * Particular CROw used as footer line on the page
- */
- class CRowFooter extends CRow
- {
- function CRowFooter(&$RefToDataMgr,$Node=NULL,$ValueType=CURRENTVALUE)
- {
- parent::CRow($RefToDataMgr,$Node,$ValueType);
- }
-
- function WriteOut(&$PageMgr)
- {
- if(!is_object($PageMgr))
- trigger_error('Internal error, WriteOut, first parameter should be an object', E_USER_ERROR);
- $evaluated=$this->DataMgr->EvalText($this->RowText);
- // var_dump($this->RowText);
- $PageMgr->WriteOutFooterRow($evaluated,$this->Align,$this->ColPos,$this->FontId);
- }
-
- }
- ?>