print = True;
}
$this->set_root($root);
}
function halt($msg)
{
echo $msg;
exit;
}
function set_root($rootdir)
{
if (!is_dir($rootdir))
{
$this->halt('set_root: '.$rootdir.' is not a directory.');
return False;
}
$this->prev_rootdir = $this->rootdir;
$this->rootdir = $rootdir;
return True;
}
function reset_root()
{
$this->rootdir = $this->prev_rootdir;
}
function add_file($filename,$rootdir='',$time=1)
{
if (!is_array($filename))
{
if($rootdir=='')
{
$rootdir=$this->rootdir;
}
if (substr($filename, 0, 1) != '/')
{
$new_filename = $rootdir.'/'.$filename;
}
else
{
$new_filename = $filename;
}
if ($this->print && $time!=2 && $time!=4)
{
$new_filename = $new_filename.'_print';
}
// echo 'Rootdir: '.$rootdir.'
'."\n".'Filename: '.$filename.'
'."\n".'New Filename: '.$new_filename.'
'."\n";
if (!file_exists($new_filename.'.xsl'))
{
switch($time)
{
case 2:
$new_root = str_replace($GLOBALS['phpgw_info']['server']['template_set'],'default',$rootdir);
$this->add_file($filename,$new_root,3);
return;
break;
case 3:
$this->add_file($filename,$rootdir,4);
return;
break;
case 4:
$this->halt("filename: file $new_filename.xsl does not exist.");
break;
default:
if (!$this->print)
{
$new_root = str_replace($GLOBALS['phpgw_info']['server']['template_set'],'default',$rootdir);
$this->add_file($filename,$new_root,4);
return;
}
else
{
$this->add_file($filename,$rootdir,2);
return;
}
}
}
else
{
$this->xslfiles[$filename] = $new_filename.'.xsl';
}
}
else
{
reset($filename);
while(list(,$file) = each($filename))
{
$this->add_file($file);
}
}
}
function set_var($name, $value, $append = False)
{
if($append)
{
if (is_array($value))
{
while(list($key,$val) = each($value))
{
$this->vars[$name][$key] = $val;
}
}
//_debug_array($this->vars);
}
else
{
$this->vars[$name] = $value;
}
}
function set_xml($xml, $append = False)
{
if(!$append)
{
$this->xmlvars = $xml;
}
else
{
$this->xmlvars .= $xml;
}
}
function get_var($name)
{
return $this->vars[$name];
}
function get_vars()
{
return $this->vars;
}
function get_xml()
{
return $this->xmlvars;
}
function xsl_parse()
{
if(count($this->xslfiles) > 0)
{
$this->xsldata = ''."\n";
$this->xsldata .= 'xsldata .= ''."\n";
$this->xsldata .= ''."\n";
$this->xsldata .= ']>'."\n";
$this->xsldata .= '
'."\n".'XSL File: '.$xslfile.'
'."\n";
$fd = fopen ($xslfile, "r");
$this->xsldata .= fread($fd, filesize($xslfile));
fclose ($fd);
}
$this->xsldata .= '
\n"; for ($n=1; isset($xml[$n]); ++$n) { echo "$n: ".htmlentities($xml[$n])."\n"; } echo "\n"; } function parse($parsexsl = True, $parsexml = True) { if($parsexsl) { $this->xsl_parse(); } if($parsexml) { $this->xml_parse(); } $xsltproc = xslt_create(); $minor = explode(".",phpversion()); if($minor[1] >= 1) // PHP 4.1.x -- preferred { $arguments = array('/_xml' => $this->xmldata, '/_xsl' => $this->xsldata); $html = xslt_process($xsltproc,'arg:/_xml','arg:/_xsl',NULL,$arguments); } else // PHP 4.0.6 -- works okay { xslt_process($this->xsldata, $this->xmldata,$html); } if (!$html) { echo "
xml-data = "; $this->list_lineno($this->xmldata); echo "
xsl-data = "; $this->list_lineno($this->xsldata); die(/*$this->xsldata.*/"\n\n XSLT processing error: ".xslt_error($xsltproc)); } xslt_free($xsltproc); return $html; } function pparse() { print $this->parse(); return False; } function pp() { return $this->pparse(); } } ?>