PHP Classes

File: PHPReport.xsl

Recommend this page to a friend!
  Classes of Eustaquio Rangel de Oliveira Jr.   phpreports   PHPReport.xsl   Download  
File: PHPReport.xsl
Role: Auxiliary data
Content type: text/plain
Description: XSLT file
Class: phpreports
Report Generator
Author: By
Last change:
Date: 21 years ago
Size: 9,075 bytes
 

Contents

Class file image Download
<?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="text" encoding="iso-8859-1" indent="no"/> <xsl:param name="user"/> <xsl:param name="pass"/> <xsl:param name="conn"/> <xsl:param name="interface"/> <xsl:param name="database"/> <xsl:param name="sql"/> <xsl:param name="classname"/> <xsl:param name="parameter1"/> <xsl:param name="parameter2"/> <xsl:param name="parameter3"/> <xsl:param name="parameter4"/> <xsl:param name="parameter5"/> <xsl:param name="reference1"/> <xsl:param name="reference2"/> <xsl:param name="reference3"/> <xsl:param name="reference4"/> <xsl:param name="reference5"/> <xsl:include href="PHPReportDoc.xsl"/> <xsl:include href="PHPReportTable.xsl"/> <xsl:include href="PHPReportCol.xsl"/> <xsl:include href="PHPReportField.xsl"/> <xsl:include href="PHPReportPage.xsl"/> <xsl:include href="PHPReportGroup.xsl"/> <xsl:include href="PHPReportXHTML.xsl"/> <xsl:template match="/"> <xsl:call-template name="MAKE_REPORT"/> </xsl:template> <!-- This is where the fun begins //--> <xsl:template name="MAKE_REPORT"> &lt;?php include '<xsl:value-of select="/REPORT/PATH"/>PHPRepoDoc.php'; include '<xsl:value-of select="/REPORT/PATH"/>PHPRepoPage.php'; include '<xsl:value-of select="/REPORT/PATH"/>PHPRepoField.php'; include '<xsl:value-of select="/REPORT/PATH"/>PHPRepoFieldURL.php'; include '<xsl:value-of select="/REPORT/PATH"/>PHPRepoRow.php'; include '<xsl:value-of select="/REPORT/PATH"/>PHPRepoDebug.php'; include '<xsl:value-of select="/REPORT/PATH"/>db_<xsl:value-of select="$interface"/>.php'; <xsl:call-template name="MAKE_DOCUMENT"/> <xsl:call-template name="MAKE_PAGE"/> <xsl:apply-templates select="/REPORT/GROUPS"/> class <xsl:value-of select="$classname"/> extends PHPRepoDebug { var $oRepoDoc; // the document object var $oRepoPage; // the page object var $oFields; // field info from the sql query var $oMainGroup; // main group to send values var $oParameters; // parameters var $bHeaders; // initial headers <xsl:for-each select="/REPORT/GROUPS/GROUP"> <xsl:call-template name="MAKE_GROUP_DECL"/> </xsl:for-each> // class constructor function <xsl:value-of select="$classname"/>() { $this->oRepoDoc = new PHPRepoDoc_(); // the document object $this->oRepoPage = new PHPRepoPage_(); // the page object $this->oFields = Array(); $this->oMainGroup = null; $this->bHeaders = false; $this->oParameters = Array(); $this->oParameters[0] = null; // nothing here <xsl:if test="string-length($parameter1)>0"> $this->oParameters[<xsl:value-of select="$reference1"/>]=&quot;<xsl:value-of select="$parameter1"/>&quot;; </xsl:if> <xsl:if test="string-length($parameter2)>0"> $this->oParameters[<xsl:value-of select="$reference2"/>]=&quot;<xsl:value-of select="$parameter2"/>&quot;; </xsl:if> <xsl:if test="string-length($parameter3)>0"> $this->oParameters[<xsl:value-of select="$reference3"/>]=&quot;<xsl:value-of select="$parameter3"/>&quot;; </xsl:if> <xsl:if test="string-length($parameter4)>0"> $this->oParameters[<xsl:value-of select="$reference4"/>]=&quot;<xsl:value-of select="$parameter4"/>&quot;; </xsl:if> <xsl:if test="string-length($parameter5)>0"> $this->oParameters[<xsl:value-of select="$reference5"/>]=&quot;<xsl:value-of select="$parameter5"/>&quot;; </xsl:if> $this->oRepoDoc->setParameters( $this->oParameters ); $this->oRepoPage->setParameters( $this->oParameters ); } // here is where the magic happens function run($bDesc=false) { <xsl:if test="string-length(/REPORT/TITLE)>0"> // set title <xsl:text>$this->oRepoDoc->setTitle( &quot;</xsl:text><xsl:value-of select="/REPORT/TITLE"/>&quot; )<xsl:text>;</xsl:text> </xsl:if> <xsl:if test="string-length(/REPORT/BACKGROUND_COLOR)>0"> // set background color <xsl:text>$this->oRepoDoc->setBackgroundColor( &quot;</xsl:text><xsl:value-of select="/REPORT/BACKGROUND_COLOR"/>&quot; )<xsl:text>;</xsl:text> </xsl:if> <xsl:if test="string-length(/REPORT/BACKGROUND_IMAGE)>0"> // set background image <xsl:text>$this->oRepoDoc->setBackgroundImg( &quot;</xsl:text><xsl:value-of select="/REPORT/BACKGROUND_IMAGE"/>&quot; )<xsl:text>;</xsl:text> </xsl:if> <xsl:if test="string-length(/REPORT/@MARGINWIDTH)>0"> // set margin width <xsl:text>$this->oRepoDoc->setMarginWidth(</xsl:text><xsl:value-of select="/REPORT/@MARGINWIDTH"/><xsl:text>);</xsl:text> </xsl:if> <xsl:if test="string-length(/REPORT/@MARGINHEIGHT)>0"> // set margin height <xsl:text>$this->oRepoDoc->setMarginHeight(</xsl:text><xsl:value-of select="/REPORT/@MARGINHEIGHT"/><xsl:text>);</xsl:text> </xsl:if> <xsl:if test="string-length(/REPORT/CSS)>0"> // if a css file exists, set its name $this->oRepoDoc->setCSS( &quot;<xsl:value-of select="/REPORT/CSS"/>&quot; ); </xsl:if> // prints the initial document tags $this->oRepoDoc->printIni(); <xsl:call-template name="MAKE_ENGINE"/> // prints the document footer $this->oRepoDoc->printFooter( null ); // if debugs ... if($bDesc) $this->debug(); // prints the final html stuff ( usually the /body and /html tags ) $this->oRepoDoc->printEnd( null ); } function getMainGroup() { return $this->oMainGroup; } } ?&gt; </xsl:template> <!-- Used to transform the DOCUMENT HEADER/FOOTER and PAGE elements of the report. Since they are HTML table elements and have the same tags as another XML elements that represents a HTML table too, it calls the MAKE_TABLE_CONFIG template to format all the table properties. //--> <xsl:template match="/REPORT/PAGE"> <xsl:call-template name="MAKE_TABLE_CONFIG"/> </xsl:template> <xsl:template match="/REPORT/DOCUMENT/HEADER"> <xsl:call-template name="MAKE_TABLE_CONFIG"/> </xsl:template> <xsl:template match="/REPORT/DOCUMENT/FOOTER"> <xsl:call-template name="MAKE_TABLE_CONFIG"/> </xsl:template> <!-- Make the main program engine //--> <xsl:template name="MAKE_ENGINE"> // open the data connection $sSQL = &quot;<xsl:value-of select="$sql"/>&quot;; $oCon = @db_connect( Array( "<xsl:value-of select='$user'/>", "<xsl:value-of select='$pass'/>","<xsl:value-of select='$conn'/>","<xsl:value-of select='$database'/>" ) ) or die( "connection refused" ); $oStmt = @db_query($oCon,$sSQL) or die("error executing query"); // get info about all the fields returned in the query $iColNum = db_colnum( $oStmt ); for( $i=0; $i&lt;$iColNum; $i++ ) $this->oFields[$i] = new PHPRepoField( db_columnName( $oStmt, $i+1 ), db_columnType( $oStmt, $i+1 ) ); // sets the fields info for the document object $this->oRepoDoc->setFields( $this->oFields ); // sets the fields info for the page object $this->oRepoPage->setFields( $this->oFields ); <xsl:if test="string-length(/REPORT/PAGE/@SIZE)>0"> // set the page size ( subtract the size of page header + page footer ) $this->oRepoPage->setPageSize( <xsl:value-of select="/REPORT/PAGE/@SIZE"/>-<xsl:value-of select="count(/REPORT/PAGE/HEADER/ROW)"/>-<xsl:value-of select="count(/REPORT/PAGE/FOOTER/ROW)"/> ); </xsl:if> // create all the groups <xsl:for-each select="/REPORT/GROUPS/GROUP"> <xsl:call-template name="MAKE_GROUP_TREE"/> </xsl:for-each> <xsl:for-each select="/REPORT/GROUPS/GROUP"> <xsl:call-template name="MAKE_GROUP_CHILD"/> </xsl:for-each> // sets the document object on the page $this->oRepoPage->setDocument( $this ); // create a flag for the initial headers $bHeaders = false; while( $aResult = db_fetch( $oStmt ) ) { // create a new row with the current row data $oRow = new PHPRepoRow(); for( $i=0; $i&lt;$iColNum; $i++ ) { $sField = $this->oFields[$i]->getName(); // get the field name $sValue = $aResult[$sField]; // get its value $sValue = ($sValue=="")?"&amp;nbsp;":$sValue; // check if is null - put a white space here $oRow->putValue($sField,$sValue); // put the value in the row } // if its the first row on the report, print the headers if( !$this->bHeaders ) { $this->bHeaders = true; $this->oRepoDoc->printHeader( $oRow ); $this->oRepoPage->printHeader( $oRow ); } // send data to the listeners // *** don't *** send to the page object here, the groups will do that !!! $this->oRepoDoc->processRow( $oRow ); $this->oMainGroup->processRow( $oRow ); } $this->oMainGroup->processRow( null ); $this->oRepoPage->printFooter( null, false ); db_free( $oStmt ); db_disconnect( $oCon ); </xsl:template> <!-- template for all text elements --> <xsl:template match="text()"> <xsl:value-of select="normalize-space()"/> </xsl:template> </xsl:stylesheet>