PageRenderTime 11ms CodeModel.GetById 54ms app.highlight 51ms RepoModel.GetById 1ms app.codeStats 1ms

/includes/php/PHPReports/PHPReportMaker.php

http://tracmor.googlecode.com/
PHP | 856 lines | 457 code | 96 blank | 303 comment | 43 complexity | e612f2138de392c900b56a23a1439373 MD5 | raw file
  1<?php
  2	include("PHPReportsUtil.php");
  3
  4	/******************************************************************************
  5	*                                                                             *
  6	*	PHPReportMaker                                                             *
  7	*	This is the main class of PHPReports                                       *
  8	*                                                                             *
  9	*	Use like this:                                                             *
 10	*	$oRpt = new PHPReportMaker();                                              *
 11	*	$oRpt->setXML("test.xml");                                                 *
 12	*	$oRpt->setXSLT("test.xsl");                                                *
 13	*	$oRpt->setUser("john");                                                    *
 14	*	$oRpt->setPassword("doe");                                                 *
 15	*	$oRpt->setConnection("mydatabaseaddr");                                    *
 16	*	$oRpt->setDatabaseInterface("oracle");                                     *
 17	*	$oRpt->setSQL("select * from mytable");                                    *
 18	*	$oRpt->run();                                                              *
 19	*                                                                             *
 20	******************************************************************************/
 21	class PHPReportMaker {
 22		var $_sPath;			// PHPReports path
 23		var $sXML;				// XML report file
 24		var $sXSLT;				// XSLT file
 25		var $sUser;				// user name
 26		var $sPass;				// password
 27		var $sCon;				// connection name
 28		var $sDataI;			// database interface
 29		var $sSQL;				// sql query command
 30		var $_oParm;			// parameters
 31		var $sDatabase;		// database
 32		var $sCodeOut;			// code output
 33		var $sOut;				// HTML result file
 34		var $bDebug;			// debug report
 35		var $_sNoDataMsg;		// no data message - NEW!!! on 0.2.0
 36		var $_sOutputPlugin;	// output plugin name - NEW!!! on 0.2.0
 37		var $_oOutputPlugin;	// output plugin - NEW!!! on 0.2.0
 38		var $_sXMLOutputFile;// XML output file with the data
 39		var $_sSaveTo;			// save to file - NEW!!! 0.2.0
 40		var $_oProc;			// XSLT processor
 41		var $_aEnv;				// enviroment vars
 42		var $_sClassName;		// report class name to create
 43		var $_sTmp;				// temporary dir
 44		var $_oCon;				// database connection handle
 45		var $_oQuery;			// executed query
 46		var $_iPageSize;		// page size
 47		var $_aBench;			// benchmark registers
 48		var $_sLang;			// language
 49		var $_bBody;			// no HTML BODY shown on the report
 50		var $_bDeleteXML;		// if needs to delete the XML file after using it
 51		var $_oError;
 52		var $_oInput;			// input plugins
 53
 54		/***************************************************************************
 55		*																									*
 56		*	Constructor - remember to set the PHPREPORTS										*
 57		*	environment variable																		*
 58		*																									*
 59		***************************************************************************/
 60		function PHPReportMaker() {
 61			$this->_sPath				= getPHPReportsFilePath();
 62			$this->_sTmp				= getPHPReportsTmpPath();
 63			$this->sXML					= null;
 64			$this->sXSLT				= $this->_sPath."/xslt/PHPReport.xsl";
 65			$this->sUser				= null;
 66			$this->sPass				= null;
 67			$this->sCon					= null;
 68			$this->sDataI				= null;
 69			$this->sSQL					= null;
 70			$this->_oParm				= Array();
 71			$this->sDatabase			= null;
 72			$this->sCodeOut			= null;
 73			$this->sOut					= null;
 74			$this->bDebug				= false;
 75			$this->_sNoDataMsg		= "";
 76			$this->_sNoDataFunc		= "";
 77			$this->_sOutputPlugin	= "default";
 78			$this->_oOutputPlugin	= null;
 79			$this->_sSaveTo			= null;
 80			$this->_aEnv				= Array();
 81			$this->_sClassName		= "PHPReport";
 82			$this->_iPageSize			= 0;
 83			$this->_aBench				= Array();
 84			$this->_sLang				= "default";
 85			$this->_bBody				= true;
 86			$this->_bDeleteXML		= false;
 87			$this->_oError				= new PHPReportsErrorTr();
 88			$this->_oInput				= Array();
 89
 90			/*
 91				Now we get the XSLT processor
 92				new code on the 0.2.8 version, because PHP5 have XSL
 93				support with libxslt, by default
 94			*/
 95			$oProcFactory = new XSLTProcessorFactory();
 96			$this->_oProc = $oProcFactory->get();
 97			if(is_null($this->_oProc))
 98				$this->_oError->showMsg("NOXSLT");
 99
100			// check path stuff
101			if(is_null(getPHPReportsFilePath()))
102				$this->_oError->showMsg("NOPATH");
103		}
104
105		/******************************************************************************
106		*																										*
107		*	Create a quick report from a layout file and some parameters.					*
108		*																										*
109		******************************************************************************/
110		function createFromTemplate($sTitle="NO DEFINED TITLE",$sFile=null,$oParms=null,$oDocument=null,$oGroups=null){
111			$sPath	= getPHPReportsFilePath();
112			$oError	= new PHPReportsErrorTr();
113			$sIf		= $this->getDatabaseInterface();
114			$sFile	= $sFile ? $sFile : realpath($sPath."/template.xml");
115
116			// if the file does not exist
117			if(!file_exists($sFile))
118				$oError->showMsg("NOTEMPLATE",$sFile);
119
120			// get the template contents
121			$sFileContents = file_get_contents($sFile);
122
123			// check if there are some parameters here ...
124			if($oParms){
125				$sParms = null;
126				if(is_object($oParms))	$sParms = $oParms->write();
127				if(is_string($oParms))	$sParms = $oParms;
128				if($sParms)
129					$sFileContents = str_replace("<REPLACE_WITH_PARAMETERS/>",$sParms,$sFileContents);
130			}
131
132			// check if there is some document info
133			if($oDocument){
134				$sDocument = null;
135				if(is_object($oDocument))	$sDocument = $oDocument->write();
136				if(is_string($oDocument))	$sDocument = $oDocument;
137				if($sDocument)
138					$sFileContents = str_replace("<REPLACE_WITH_DOCUMENT_INFO/>",$sDocument,$sFileContents);
139			}
140
141			// if no groups info was specified, follow the default behaviour: all the fields from the query,
142			// with no group break
143			if(!$oGroups){
144				// include the database interface and try to open the connection and execute the query
145				$sIfFile = realpath($sPath."/database/db_".$sIf.".php");
146				if(!file_exists($sIfFile))
147					$oError->showMsg("NOIF",$sIf);
148				include_once $sIfFile;
149
150				// if the database connection is null, open it
151				if(is_null($this->_oCon))
152					$this->_oCon = @PHPReportsDBI::db_connect(Array($this->sUser,$this->sPass,$this->sCon,$this->sDatabase)) or $oError->showMsg("REFUSEDCON");
153
154				// if there are some input filters ...
155				if($this->_oInput){
156					foreach($this->_oInput as $oFilter){
157						$oFilter->setConnection($this->_oCon);
158						$oFilter->setSQL(trim($this->sSQL));
159						$this->sSQL = trim($oFilter->run());
160					}
161					// there is no need to run the filters again
162					$this->_oInput = null;
163				}
164
165				// run the query
166				$this->_oQuery = @PHPReportsDBI::db_query($this->_oCon,trim($this->sSQL)) or $oError->showMsg("QUERYERROR");
167
168				// insert the column names
169				$sNames				= "";
170				$sReplacedNames	= "";
171
172				$iColNum = PHPREportsDBI::db_colnum($this->_oQuery);
173				for($i=1; $i<=$iColNum; $i++){
174					$sName				= PHPReportsDBI::db_columnName($this->_oQuery,$i);
175					$sExtra				= isNumericType(PHPReportsDBI::db_columnType($this->_oQuery,$i))?" ALIGN=\"RIGHT\"":"";
176					$sReplacedNames  .= "<COL CELLCLASS=\"bold\"$sExtra>".ucfirst(strtolower(str_replace("_"," ",$sName)))."</COL>";
177					$sNames			  .= "<COL TYPE=\"FIELD\"$sExtra>$sName</COL>";
178				}
179
180				// build the group info
181				$sGroup			= "<GROUP REPRINT_HEADER_ON_PAGEBREAK='TRUE'><HEADER><ROW><REPLACE_WITH_REPLACED_COLUMN_NAMES/></ROW></HEADER><FIELDS><ROW><REPLACE_WITH_COLUMN_NAMES/></ROW></FIELDS></GROUP>";
182				$sGroup			= str_replace("<REPLACE_WITH_REPLACED_COLUMN_NAMES/>",$sReplacedNames,$sGroup);
183				$sGroup			= str_replace("<REPLACE_WITH_COLUMN_NAMES/>",$sNames,$sGroup);
184				$sFileContents = str_replace("<REPLACE_WITH_GROUP_INFO/>",$sGroup,$sFileContents);
185			}else{
186				$sGroups = null;
187				if(is_object($oGroups))	$sGroups	= $oGroups->write();
188				if(is_string($oGroups))	$sGroups = $oGroups;
189				if($sGroups)
190					$sFileContents = str_replace("<REPLACE_WITH_GROUP_INFO/>",$sGroups,$sFileContents);
191			}
192
193			// replace the report title
194			$sFileContents = str_replace("<REPLACE_WITH_TITLE/>",$sTitle,$sFileContents);
195			// print htmlspecialchars($sFileContents);
196
197			// create the temporary XML file
198			$sTemp = tempnam($this->_sTmp,"tempphprpt");
199
200			// this is just for PHP4 compability
201			$fHand = fopen($sTemp,"w");
202			fwrite($fHand,$sFileContents);
203			fclose($fHand);
204
205			$this->_bDeleteXML	= true;		// flag to delete the temporary file
206			$this->sXML				= $sTemp;	// the XML layout file is the temporary file now
207		}
208
209		/******************************************************************************
210		*																										*
211		*	Run report																						*
212		*	Here is where things happens. :-)														*
213		*																										*
214		******************************************************************************/
215		function run() {
216			$iReportStart = time();
217
218			// create the parameters array
219			$aParm["user"     ]	= $this->sUser;			// set user
220			$aParm["pass"     ]	= $this->sPass;			// set password
221			$aParm["conn"     ]	= $this->sCon;				// set connection name
222			$aParm["interface"]	= $this->sDataI;			// set database interface
223			$aParm["database" ]	= $this->sDatabase;		// set database
224			$aParm["classname"]	= $this->_sClassName;	// ALWAYS use this class to run the report
225			$aParm["sql"      ]	= $this->sSQL;				// set the sql query
226			$aParm["nodatamsg"]	= $this->_sNoDataMsg;	// no data msg
227			$aParm["nodatafunc"] = $this->_sNoDataFunc;	// no data function
228			$aParm["pagesize"]	= $this->_iPageSize>0?$this->_iPageSize:"";
229			$aParm["language"]	= $this->_sLang;
230
231			// create the parameters keys array - with element numbers or element keys
232			$aKeys = null;
233			if(is_array($this->_oParm)){
234				$aKeys = array_keys($this->_oParm);
235				$iSize = sizeof($this->_oParm);
236				for($i=0; $i<$iSize; $i++){
237					$sOkey = $aKeys[$i];	// original key
238					$sKey	 = $sOkey;		// reference key
239
240					// check if its a numeric key - if so, add 1 to
241					// it to keep the parameters based on 1 and not on 0
242					if(is_numeric($sOkey))
243						$sKey = intval($sOkey)+1;
244
245					$aParm["parameter".($i+1)] = $this->_oParm[$sOkey];
246					$aParm["reference".($i+1)] = $sKey;
247				}
248			}
249
250			// if there is not a file to create the code,
251			// create it on the memory (faster, use file just for
252			// debugging stuff)
253			if(is_null($this->sCodeOut)) {
254				$sOut = null;
255				$aParm["output_format"]="memory";
256			}else{
257				$sOut = $this->sCodeOut;
258				$aParm["output_format"]="file";
259			}
260
261			// XSLT processing
262			$this->_aBench["code_start"] = time();
263			$this->_oProc->setXML($this->sXML);
264			$this->_oProc->setXSLT($this->sXSLT);
265			$this->_oProc->setOutput($sOut);
266			$this->_oProc->setParms($aParm);
267			$sRst = $this->_oProc->run();
268			$this->_aBench["code_end"] = time();
269
270			$this->_aBench["code_eval_start"] = time();
271			// if its created on the memory ...
272			if(is_null($sOut))
273				eval($sRst);
274			else {
275			// include the generated classes, if it was created
276				if(!file_exists($sOut))
277					$this->_oError->showMsg("NOCODE",array($sOut));
278				require_once($sOut);
279			}
280			$this->_aBench["code_eval_end"] = time();
281
282			// include the generated class
283			$oReport = new $this->_sClassName;
284
285			// set the database connection handle, if there is one
286			$oReport->setDatabaseConnection($this->_oCon);
287			$oReport->setInputFilters($this->_oInput);
288			$oReport->setQuery($this->_oQuery);
289
290			// run the generated class
291			$this->_sXMLOutputFile = $oReport->run($this->_sXMLOutputFile,$this->_aEnv);
292			$this->_aBench = array_merge($this->_aBench,$oReport->getBenchmarks());
293
294			// check if the XML file exists, we need data!
295			if(!file_exists($this->_sXMLOutputFile))
296				$this->_oError->showMsg("NOXML",array($this->_sXMLOutputFile));
297
298			/*
299				Now we have a XML file with the report contents ... what to to with it???
300				Let's call the output plugin!
301			*/
302
303			//	if there is no one, create a new default plugin
304			$oOut = null;
305			if(is_null($this->_oOutputPlugin)) {
306				$oOut = $this->createOutputPlugin("default");
307				$oOut->setInput ($this->_sXMLOutputFile);
308				$oOut->setOutput($this->sOut);
309				$oOut->setBody($this->_bBody);
310				$this->setOutputPlugin($oOut);
311			}else{
312				$oOut = $this->_oOutputPlugin;
313				$oOut->setBody($this->_bBody);
314				$oOut->setInput($this->_sXMLOutputFile);
315				if(!is_null($this->sOut))
316					$oOut->setOutput($this->sOut);
317			}
318
319			// if need to save it
320			if(!is_null($this->_sSaveTo))
321				$this->save();
322
323			// run
324			$oOut->run();
325			$this->_aBench["output_end"] = time();
326			$this->_aBench["report_start"] = $iReportStart;
327			$this->_aBench["report_end"] = time();
328
329			// if needs to delete the XML file
330			if($this->_bDeleteXML)
331				unlink($this->sXML);
332			return $this->_sXMLOutputFile;
333		}
334
335		/******************************************************************************
336		*	Return a (or all) benchmark index.														*
337		******************************************************************************/
338		function getBenchmark($sId=null){
339			if(!$sId)
340				return $this->_aBench;
341			return $this->_aBench[$sId];
342		}
343
344		/******************************************************************************
345		*	Set the page size (overrides XML value)												*
346		******************************************************************************/
347		function setPageSize($iSize=50){
348			$this->_iPageSize=$iSize;
349		}
350		function getPageSize(){
351			return $this->_iPageSize;
352		}
353
354		/******************************************************************************
355		*																										*
356		*	Set the XML file path																		*
357		*	@param String file path																		*
358		*																										*
359		******************************************************************************/
360		function setXML($sXML_) {
361			if(!file_exists($sXML_))
362				$this->_oError->showMsg("NOXMLSET",array($sXML_));
363			$this->sXML = $sXML_;
364		}
365
366		/******************************************************************************
367		*																										*
368		*	Returns the XML file path																	*
369		*	@return String file path																	*
370		*																										*
371		******************************************************************************/
372		function getXML() {
373			return $this->sXML;
374		}
375
376		/******************************************************************************
377		*																										*
378		*	Sets the XSLT file path																		*
379		*	@param String file path																		*
380		*																										*
381		******************************************************************************/
382		function setXSLT($sXSLT_) {
383			if(!file_exists($sXSLT_))
384				$this->_oError->showMsg("NOXSLTSET",array($sXSLT_));
385			$this->sXSLT = $sXSLT_;
386		}
387
388		/******************************************************************************
389		*																										*
390		*	Returns the XSLT file path																	*
391		*	@return String file path																	*
392		*																										*
393		******************************************************************************/
394		function getXSLT() {
395			return $this->sXSLT;
396		}
397
398		/******************************************************************************
399		*																										*
400		*	Set the user name																				*
401		*	@param String user name																		*
402		*																										*
403		******************************************************************************/
404		function setUser($sUser_) {
405			$this->sUser = $sUser_;
406		}
407
408		/******************************************************************************
409		*																										*
410		*	Returns the user name																		*
411		*	@return String user name																	*
412		*																										*
413		******************************************************************************/
414		function getUser() {
415			return $this->sUser;
416		}
417
418		/******************************************************************************
419		*																										*
420		*	Sets the password																				*
421		*																										*
422		******************************************************************************/
423		function setPassword($sPass_) {
424			$this->sPass = $sPass_;
425		}
426
427		/******************************************************************************
428		*																										*
429		*	Returns the password																			*
430		*																										*
431		******************************************************************************/
432		function getPassword() {
433			return $this->sPass;
434		}
435
436		/******************************************************************************
437		*																										*
438		*	Sets the database connection																*
439		*																										*
440		******************************************************************************/
441		function setConnection($sCon_) {
442			$this->sCon = $sCon_;
443		}
444
445		/******************************************************************************
446		*																										*
447		*	Returns the password																			*
448		*																										*
449		******************************************************************************/
450		function getConnection() {
451			return $this->sCon;
452		}
453
454		/******************************************************************************
455		*																										*
456		*	Sets the database interface																*
457		*																										*
458		******************************************************************************/
459		function setDatabaseInterface($sData_) {
460			$this->sDataI = $sData_;
461		}
462
463		/******************************************************************************
464		*																										*
465		*	Returns the database interface															*
466		*																										*
467		******************************************************************************/
468		function getDatabaseInterface() {
469			return $this->sDataI;
470		}
471
472		/******************************************************************************
473		*																										*
474		*	Sets the SQL query																			*
475		*																										*
476		******************************************************************************/
477		function setSQL($sSQL_) {
478			$this->sSQL = $sSQL_;
479		}
480
481		/******************************************************************************
482		*																										*
483		*	Returns the SQL query																		*
484		*																										*
485		******************************************************************************/
486		function getSQL() {
487			return $this->sSQL;
488		}
489
490		/******************************************************************************
491		*																										*
492		*	Sets the parameters																			*
493		*																										*
494		******************************************************************************/
495		function setParameters($oParm_) {
496			$this->_oParm = $oParm_;
497		}
498
499		/******************************************************************************
500		*																										*
501		*	Returns the parameters																		*
502		*																										*
503		******************************************************************************/
504		function getParameters() {
505			return $this->_oParm;
506		}
507
508		/******************************************************************************
509		*																										*
510		*	Sets the database																				*
511		*																										*
512		******************************************************************************/
513		function setDatabase($sData_) {
514			$this->sDatabase = $sData_;
515		}
516
517		/******************************************************************************
518		*																										*
519		*	Returns the database																			*
520		*																										*
521		******************************************************************************/
522		function getDatabase() {
523			return $this->sDatabase;
524		}
525
526		/******************************************************************************
527		*																										*
528		*	Sets the code output file																	*
529		*																										*
530		******************************************************************************/
531		function setCodeOutput($sFile_) {
532			$this->sCodeOut = $sFile_;
533		}
534
535		/******************************************************************************
536		*																										*
537		*	Returns the database																			*
538		*																										*
539		******************************************************************************/
540		function getCodeOutput() {
541			return $this->sCodeOut;
542		}
543
544		/******************************************************************************
545		*																										*
546		*	Sets the output path																			*
547		*																										*
548		******************************************************************************/
549		function setOutput($sOut_) {
550			$this->sOut = $sOut_;
551		}
552
553		/******************************************************************************
554		*																										*
555		*	Returns output path																			*
556		*																										*
557		******************************************************************************/
558		function getOutput() {
559			return $this->sOut;
560		}
561
562		/******************************************************************************
563		*																										*
564		*	Sets if the report will generate debug info after it runs						*
565		*																										*
566		******************************************************************************/
567		function setDebug($bDesc) {
568			$this->bDebug = $bDesc;
569		}
570
571		/******************************************************************************
572		*																										*
573		*	Returns if will debug																		*
574		*																										*
575		******************************************************************************/
576		function getDebug() {
577			return $this->bDebug;
578		}
579
580		/******************************************************************************
581		*																										*
582		*	Sets message to be shown when no data returns from the query					*
583		*	@param String message																		*
584		*																										*
585		******************************************************************************/
586		function setNoDataMsg($sMsg_="") {
587			$this->_sNoDataMsg=$sMsg_;
588		}
589
590		/******************************************************************************
591		*																										*
592		*	Returns the no data message																*
593		*	@return String message																		*
594		*																										*
595		******************************************************************************/
596		function getNoDataMsg() {
597			return $this->_sNoDataMsg;
598		}
599
600		function setNoDataFunc($sFunc=""){
601			$this->_sNoDataFunc=$sFunc;
602		}
603
604		function getNoDataFunc(){
605			return $this->_sNoDataFunc;
606		}
607
608		/******************************************************************************
609		*																										*
610		*	Create the output plugin																	*
611		*	@param name																						*
612		*																										*
613		******************************************************************************/
614		function createOutputPlugin($sName_) {
615			$sFullPath = $this->_sPath."/output/$sName_/PHPReportOutput.php";
616
617			// check if the required plugin exists
618			if(!file_exists($sFullPath))
619				$this->_oError->showMsg("NOPLUGIN",array($sName_,$sFullPath));
620			include $sFullPath;
621
622			$oOut = new PHPReportOutput($this->sXML);
623			return $oOut;
624		}
625
626		function addInputPlugin($sName_,$oGroupDesc_,$sGroupKey_,$oOptions_=null){
627			$sName  = ucwords(strtolower($sName_));
628			$sClass = "PHPReportInput$sName";
629			$sFullPath = $this->_sPath."/input/PHPReportInput$sName.php";
630
631			// check if the required plugin exists
632			if(!file_exists($sFullPath))
633				$this->_oError->showMsg("NOPLUGIN",array($sName_,$sFullPath));
634			include $sFullPath;
635
636			$oIn = new $sClass($oGroupDesc_,$sGroupKey_,$oOptions_);
637			array_push($this->_oInput,$oIn);
638		}
639
640		/******************************************************************************
641		*																										*
642		*	Output plugin for the final format														*
643		*	@param plugin																					*
644		*																										*
645		******************************************************************************/
646		function setOutputPlugin($oPlugin_) {
647			$this->_oOutputPlugin=$oPlugin_;
648		}
649
650		/******************************************************************************
651		*																										*
652		*	Returns the output plugin																	*
653		*	@return plugin																					*
654		*																										*
655		******************************************************************************/
656		function getOutputPlugin() {
657			return $this->_oOutputPlugin;
658		}
659
660		/******************************************************************************
661		*																										*
662		*	Set the XML output/data file																*
663		*																										*
664		******************************************************************************/
665		function setXMLOutputFile($sFile_=null){
666			$this->_sXMLOutputFile=$sFile_;
667		}
668
669		/******************************************************************************
670		*																										*
671		*	Returns the XML output/data file															*
672		*																										*
673		******************************************************************************/
674		function getXMLOutputFile(){
675			return $this->_sXMLOutputFile;
676		}
677
678		/******************************************************************************
679		*																										*
680		*	File path to save the report																*
681		*	Please remember to use a writable path!												*
682		*																										*
683		******************************************************************************/
684		function saveTo($sFile_=null){
685			if(is_null($sFile_))
686				return;
687			$this->_sSaveTo=$sFile_;
688		}
689
690		/******************************************************************************
691		*																										*
692		*	Save report																						*
693		*																										*
694		******************************************************************************/
695		function save(){
696			if(is_null($this->_sSaveTo))
697				return;
698			$sIn  = $this->_sXMLOutputFile;
699			$sMD5 = md5_file($sIn);		// calculate the md5 checksum
700			$sMD5	= str_pad($sMD5,50);	// padding
701			$sOut = "compress.zlib://".$this->_sSaveTo;
702			$fIn	= fopen($sIn,"r");
703			$fOut = fopen($sOut,"w");
704
705			// write the md5sum
706			fwrite($fOut,$sMD5);
707
708			while($sStr=fread($fIn,1024))
709				fwrite($fOut,$sStr);
710			fclose($fOut);
711			fclose($fIn);
712		}
713
714		/******************************************************************************
715		*																										*
716		*	Preview report																					*
717		*																										*
718		******************************************************************************/
719		function preview($sXML_=null){
720			if(is_null($sXML_))
721				return;
722
723			if(!file_exists($sXML_)){
724				print "<b>The file $sXML_ doesn't exists.</b><br>";
725				return;
726			}
727
728			$sPath  = getPHPReportsFilePath();
729			$sXSLT  = "$sPath/xslt/PHPReportPreview.xsl";
730
731			// XSLT processing
732			$this->_oProc->setXML($sXML_);
733			$this->_oProc->setXSLT($sXSLT);
734			print $this->_oProc->run();
735		}
736
737		/******************************************************************************
738		*																										*
739		*	Put an object to the environment array.												*
740		*	You can use this function to expose any kind of variable or class to your	*
741		*	report (using <COL>$this->getEnv("id")</COL>). Note that for using objects	*
742		*	returned by this function directly as													*
743		*	<COL>$this->getEnv("id")->myFunction()</COL>											*
744		*	you'll need PHP5.																				*
745		*																										*
746		******************************************************************************/
747		function putEnvObj($sKey_=null,$oObj_=null){
748			if(is_null($sKey_) ||
749				is_null($oObj_))
750				return;
751			$this->_aEnv[$sKey_]=$oObj_;
752		}
753
754		/******************************************************************************
755		*																										*
756		*	Returns an object from the environment array.										*
757		*																										*
758		******************************************************************************/
759		function getEnvObj($sKey_){
760			return $this->_aEnv[$sKey_];
761		}
762
763		/******************************************************************************
764		*																										*
765		*	Set the name of the class that will be created										*
766		*	to run the report.																			*
767		*	To see where this name is used, please check xslt/PHPReport.xsl				*
768		*																										*
769		******************************************************************************/
770		function setClassName($sClassName_="PHPReport"){
771			$this->_sClassName=$sClassName_;
772		}
773
774		/******************************************************************************
775		*																										*
776		*	Returns the name of the class that will be created									*
777		*	to run the report.																			*
778		*																										*
779		******************************************************************************/
780		function getClassName(){
781			return is_null($this->_sClassName)?"PHPReport":$this->_sClassName;
782		}
783
784		/******************************************************************************
785		*																										*
786		*	Set the database connection handle														*
787		*																										*
788		******************************************************************************/
789		function setDatabaseConnection(&$_oCon){
790			$this->_oCon =& $_oCon;
791		}
792
793		/******************************************************************************
794		*																										*
795		*	Here's the deal: if the user have a session opened, the language will be	*
796		*	stored there. If more than one user is using the system with different		*
797		*	languages, each one will see the specified language (no way to run two		*
798		*	reports with different languages for each user). If no session is opened,	*
799		*	the language value is already there on GLOBALS, so we can retrieve from		*
800		*	there, but this will allow just one language for all the reports.				*
801		*																										*
802		******************************************************************************/
803		function setLanguage($sLang_="default"){
804			$this->_sLang=$sLang_;
805			$_SESSION["phpReportsLanguage"] = $sLang_;
806			$GLOBALS["phpReportsLanguage"] = $sLang_;
807		}
808
809		function getLanguage(){
810			return $this->_sLang;
811		}
812
813		function setBody($b=true){
814			$this->_bBody=$b;
815		}
816
817		function getBody(){
818			return $this->_bBody;
819		}
820	}
821
822	class PHPReportTemplateElement {
823		var $_aAttrs;
824		var $_aChildren;
825		var $_sType;
826
827		function PHPReportTemplateElement($sType=null,$aAttrs=null){
828			$this->_sType		= $sType;
829			$this->_aChildren	= array();
830			$this->_aAttrs		= $aAttrs ? $aAttrs : array();
831		}
832
833		function addAttr($sKey,$sValue){
834			$this->_aAttrs[$sKey]=$sValue;
835		}
836
837		function addChild($oChild){
838			array_push($this->_aChildren,$oChild);
839		}
840
841		function write(){
842			if($this->_sType){
843				$sStr = "<".$this->_sType;
844				foreach($this->_aAttrs as $sKey=>$sValue)
845					$sStr .= strtoupper($sKey)=="VALUE"?"":" $sKey=\"$sValue\" ";
846				$sStr .= ">";
847			}
848			$sStr .= $this->_aAttrs["VALUE"];
849			foreach($this->_aChildren as $oChild)
850				$sStr .= $oChild->write();
851			if($this->_sType)
852				$sStr .= "</".$this->_sType.">";
853			return $sStr;
854		}
855	}
856?>