<?php
/*
*******************************************************************************
FiReportXML -- Rapid XML Report Generator
Copyright (C) 2004 Daniel McFeeters
included with
FiForms -- A collection of PHP classes designed
to facilitate rapid development of web-database software
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU 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
General Public License for more details.
You should have received a copy of the GNU 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
The original author of this library can be contacted at the following
address:
Daniel McFeeters
182 Baker Rd.
Faubush, KY 42544-6526
email:databases [at] fiforms [dot] org
http://www.fiforms.org/
Project Started January 20, 2004
*******************************************************************************
FiReports_xsltWrapper.inc.php
*******************************************************************************
*/
if(!isset($FIFORMS_CONFIG))
{
die('No Configuration found. Did you perhaps call an include file' .
' directly instead of calling it as part of the FiForms' .
' application?');
}
/* ?><code><?php */
class xsltWrapper
// Wrapper for XSLT Functions
{
public $params; // array of parameters
public $errorMsg; // Error Messages
function xsltWrapper()
{
$this->params = array();
}
function transformFileByFile($xmlFile,$xsltFile)
{
$xml = file_get_contents($xmlFile);
return $this->transformStringByFile($xml,$xsltFile);
}
function transformStringByFile($xmlString,$xsltFile)
{
if($GLOBALS['FIFORMS_CONFIG']['PHP_XSLT'] == TRUE)
{
$sheet = new DOMDocument() or die("Error Creating DOMDocument");
$sheet->validateOnParse = false;
$sheet->resolveExternals = false;
$sheet->load($xsltFile) or die("Error Loading XSLT stylesheet.");
$xsl = new XSLTProcessor() or die("Error creating XSLT Processor.");
$xsl->importStyleSheet($sheet);// or die("Error loading sheet");
$doc = new DOMDocument();
$doc->validateOnParse = false;
$doc->resolveExternals = false;
$er = $doc->loadXML($xmlString);
// FIXME Need to load parameters wtih setParameter('',name,value);
foreach($this->params as $key => $param)
{
if(trim($key) !== "")
{
$xsl->setParameter('',$key,$param);
}
}
if(!$er)
{
$this->errorMsg .= "Error Loading XML";
return false;
}
return $xsl->transformToXML($doc);
}
else
{
$descriptorspec = array(
0 => array("pipe", "r"),
1 => array("pipe", "w"),
2 => array("pipe", "w")
);
chdir($GLOBALS['FIFORMS_CONFIG']['SCRIPT_PATH']);
$pipes = array();
$stringParams = "";
foreach($this->params as $key => $param)
{
if(trim($key) !== "" && trim($param) !== "")
{
$stringParams .= " --stringparam ".
escapeshellarg($key)." ".escapeshellarg($param);
}
}
$cmd = $GLOBALS['FIFORMS_CONFIG']['XSLTPROC'].$stringParams." --nowrite --nomkdir --nonet $xsltFile -";
$process = proc_open($cmd, $descriptorspec, $pipes);
$result = "";
$error = "";
if (is_resource($process))
{
fwrite($pipes[0], $xmlString);
fclose($pipes[0]);
while (!feof($pipes[1]))
{
$result .= fgets($pipes[1], 1024);
}
fclose($pipes[1]);
while (!feof($pipes[2]))
{
$error .= fgets($pipes[2], 1024);
}
fclose($pipes[2]);
proc_close($process);
} // if is_resource
if(!$result)
{
$this->errorMsg .= "Error executing ".$GLOBALS['FIFORMS_CONFIG']['XSLTPROC'].". Please insure that xsltproc is properly installed and that FiReports is configured properly in FiForms_global.inc.php.\n\nThe following command produced an error:\n\n$cmd\n\n";
$this->errorMsg .= $error;
return false;
}
return($result);
}
} // function transformStringByFile
} // class xsltWrapper
/* ?></code><?php */
?>